Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.contactBaseData.backend into DEVELOP
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java b/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java
index c62049a..01ae819 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java
@@ -19,6 +19,12 @@
public static final String ADDRESS_TYPE_UUID_NOT_EXISTING = "addressType.uuid.not.existing";
public static final String CONTACT_UUID_NOT_EXISTING = "contact.uuid.not.existing";
public static final String MODULE_ASSIGNMENT_UUID_NOT_EXISTING = "module.assignment.uuid.not.existing";
+ public static final String ANONYMOUS_TAG = "***";
+ public static final String ADDRESS_UUID_NOT_EXISTING = "address.uuid.not.existing";
+ public static final String COMMUNICATION_UUID_NOT_EXISTING = "communication.uuid.not.existing";
+ public static final String COMMUNICATION_TYPE_UUID_NOT_EXISTING = "communication.type.uuid.not.existing";
+ public static final String COMMUNICATION_TYPE_ALREADY_EXISTING_FOR_CONTACT = "communication.type.already.existing.for.contact";
+ public static final String SALUTATION_UUID_NOT_EXISTING = "salutation.uuid.not.existing";
private Constants() {
// empty Constructor for the sake of SONAR
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java
index 97d2568..f425049 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java
@@ -19,9 +19,7 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
-import org.eclipse.openk.contactbasedata.service.AddressService;
import org.eclipse.openk.contactbasedata.service.CommunicationService;
-import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
import org.eclipse.openk.contactbasedata.viewmodel.CommunicationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/CompanyController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/CompanyController.java
index b16586a..b42e692 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/CompanyController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/CompanyController.java
@@ -36,6 +36,7 @@
import java.net.URI;
import java.util.List;
+import java.util.Optional;
import java.util.UUID;
@Log4j2
@@ -62,8 +63,9 @@
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
public Page<CompanyDto> readCompanys(
+ @RequestParam( "alsoShowAnonymous") Optional<Boolean> alsoShowAnonymous,
@PageableDefault(sort = {"companyName"}, direction = Sort.Direction.ASC) Pageable pageable){
- return companyService.findCompanies(pageable);
+ return companyService.findCompanies(alsoShowAnonymous.orElse(false), pageable);
}
@PostMapping
@@ -107,9 +109,12 @@
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
@ApiResponse(code = 404, message = "Ansprechpartner wurden nicht gefunden")})
- public List<ContactPersonDto> findContactPersons(@PathVariable("contactUuid") UUID contactUuid) {
+ public List<ContactPersonDto> findContactPersons(
+ @PathVariable("contactUuid") UUID contactUuid,
+ @RequestParam("alsoShowAnonymous") Optional<Boolean> alsoShowAnonymous ) {
- return companyService.findContactPersonsToCompany(contactUuid);
+ return companyService.findContactPersonsToCompany(
+ contactUuid, alsoShowAnonymous.orElse(false));
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java
index faf8b5a..54def44 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java
@@ -19,12 +19,15 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
+import org.eclipse.openk.contactbasedata.service.ContactAnonymizerService;
import org.eclipse.openk.contactbasedata.service.ContactService;
+import org.eclipse.openk.contactbasedata.service.util.SearchContactsFilterParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
@@ -40,6 +43,9 @@
@Autowired
private ContactService contactService;
+ @Autowired
+ private ContactAnonymizerService contactAnonymizerService;
+
@ApiOperation(value = "Anzeigen aller gespeicherter Kontakte")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@ResponseStatus(HttpStatus.OK)
@@ -52,15 +58,35 @@
@RequestParam( "moduleName") Optional<String> moduleName,
@RequestParam( "withoutAssignedModule") Optional<Boolean> withoutAssignedModule,
@RequestParam( "expiringDataInPast" ) Optional<Boolean> expiringDataInPast,
+ @RequestParam( "deletionLockExceeded") Optional<Boolean> delLockExceeded,
+ @RequestParam( "alsoShowAnonymized" ) Optional<Boolean> showAnonymized,
@PageableDefault( sort = {"name"}, size = 20, direction = ASC) Pageable pageable ) {
+
+ SearchContactsFilterParams filter = new SearchContactsFilterParams();
+ filter.setContactType(contactType.orElse(null));
+ filter.setPersonTypeUuid(personTypeUuid.orElse(null));
+ filter.setSearchText(searchText.orElse(null));
+ filter.setModuleName(moduleName.orElse(null));
+ filter.setWithoutModule(withoutAssignedModule.orElse(Boolean.FALSE));
+ filter.setExpiringDataInPast(expiringDataInPast.orElse(Boolean.FALSE));
+ filter.setDelLockExceeded(delLockExceeded.orElse(Boolean.FALSE));
+ filter.setShowAnonymized(showAnonymized.orElse(Boolean.FALSE));
+
return contactService.findDetailedContacts(
- contactType.orElse(null),
- personTypeUuid.orElse(null),
- searchText.orElse( null),
- moduleName.orElse(null),
- withoutAssignedModule.orElse(Boolean.FALSE),
- expiringDataInPast.orElse(Boolean.FALSE),
- pageable);
+ filter, pageable);
}
+ @ApiOperation(value = "Anonymisieren eines Kontaktes")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Kontakt wurde anonymisiert"),
+ @ApiResponse(code = 404, message = "Nicht gefunden")})
+ @ResponseStatus(HttpStatus.OK)
+ @Secured({"ROLE_KON-WRITER", "ROLE_KON-ADMIN"})
+ @PutMapping("/{contactUuid}/anonymize")
+ public ResponseEntity anonymizeContact(
+ @PathVariable("contactUuid") String contactUuid) {
+
+ contactAnonymizerService.anonymize(UUID.fromString(contactUuid));
+ return ResponseEntity.ok().build();
+ }
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonController.java
index 86a5f3f..6ea0938 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonController.java
@@ -34,6 +34,7 @@
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.net.URI;
+import java.util.Optional;
import java.util.UUID;
@Log4j2
@@ -60,8 +61,9 @@
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
public Page<ExternalPersonDto> readExternalPersons(
+ @RequestParam( "alsoShowAnonymous") Optional<Boolean> alsoShowAnonymous,
@PageableDefault(sort = {"lastName"}, direction = Sort.Direction.ASC) Pageable pageable){
- return externalPersonService.findExternalPersons(pageable);
+ return externalPersonService.findExternalPersons(alsoShowAnonymous.orElse(false), pageable);
}
@PostMapping
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/InternalPersonController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/InternalPersonController.java
index adf51c8..bd7639d 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/InternalPersonController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/InternalPersonController.java
@@ -63,8 +63,10 @@
public Page<InternalPersonDto> readInternalPersons(
@RequestParam( "uid") Optional<String> uid,
@RequestParam( "userRef" ) Optional<String> userRef,
+ @RequestParam( "alsoShowAnonymous" ) Optional<Boolean> alsoShowAnonymous,
@PageableDefault(sort = {"lastName"}, direction = Sort.Direction.ASC) Pageable pageable){
return internalPersonService.findInternalPersons(
+ alsoShowAnonymous.orElse( false ),
uid.orElse(null ),
userRef.orElse(null ),
pageable);
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/ConflictException.java b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/ConflictException.java
index a0398b5..73c0a1f 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/ConflictException.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/ConflictException.java
@@ -19,11 +19,6 @@
@ResponseStatus(code = HttpStatus.CONFLICT)
public class ConflictException extends RuntimeException{
-
- public ConflictException() {
-
- }
-
public ConflictException(String message) {
super(message);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/InternalServerErrorException.java b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/InternalServerErrorException.java
new file mode 100644
index 0000000..bda321d
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/InternalServerErrorException.java
@@ -0,0 +1,25 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.contactbasedata.exceptions;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
+public class InternalServerErrorException extends RuntimeException{
+ public InternalServerErrorException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/OperationDeniedException.java b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/OperationDeniedException.java
index f4440ae..6ae1332 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/OperationDeniedException.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/OperationDeniedException.java
@@ -6,11 +6,6 @@
@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE)
public class OperationDeniedException extends RuntimeException{
-
- public OperationDeniedException() {
-
- }
-
public OperationDeniedException(OperationType operation, String message) {super(message);
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/UnauthorizedException.java b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/UnauthorizedException.java
index ab9864e..7c65132 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/exceptions/UnauthorizedException.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/exceptions/UnauthorizedException.java
@@ -5,11 +5,6 @@
@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
public class UnauthorizedException extends RuntimeException{
-
- public UnauthorizedException() {
-
- }
-
public UnauthorizedException(String message) {
super(message);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/mapper/CompanyMapper.java b/src/main/java/org/eclipse/openk/contactbasedata/mapper/CompanyMapper.java
index 662f832..ec3e9a0 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/mapper/CompanyMapper.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/mapper/CompanyMapper.java
@@ -27,6 +27,8 @@
@Mapping( source="contact.uuid", target="contactUuid"),
@Mapping( source="contact.contactType", target="contactType"),
@Mapping( source="contact.note", target="contactNote"),
+ @Mapping( source="contact.anonymized", target="contactAnonymized"),
+
})
CompanyDto toCompanyDto(TblCompany tblCompany);
@@ -34,6 +36,7 @@
@Mapping( source="contactUuid", target="contact.uuid"),
@Mapping( source="contactType", target="contact.contactType"),
@Mapping( source="contactNote", target="contact.note"),
+ @Mapping( source="contactAnonymized", target="contact.anonymized"),
})
TblCompany toTblCompany(CompanyDto companyDto);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/mapper/ContactPersonMapper.java b/src/main/java/org/eclipse/openk/contactbasedata/mapper/ContactPersonMapper.java
index b77906e..2f1cc24 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/mapper/ContactPersonMapper.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/mapper/ContactPersonMapper.java
@@ -28,6 +28,7 @@
@Mapping( source="contact.uuid", target="contactUuid"),
@Mapping( source="contact.contactType", target="contactType"),
@Mapping( source="contact.note", target="contactNote"),
+ @Mapping( source="contact.anonymized", target="contactAnonymized"),
@Mapping( source="refPersonType.uuid", target="personTypeUuid"),
@Mapping( source="refPersonType.type", target="personType"),
@Mapping( source="salutation.uuid", target="salutationUuid"),
@@ -52,6 +53,7 @@
@Mapping( source="companyName", target="company.companyName"),
@Mapping( source="companyType", target="company.companyType"),
@Mapping( source="companyHrNumber", target="company.hrNumber"),
+ @Mapping( source="contactAnonymized", target="contact.anonymized"),
})
TblContactPerson toTblContactPerson(ContactPersonDto contactPersonDto);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/mapper/ExternalPersonMapper.java b/src/main/java/org/eclipse/openk/contactbasedata/mapper/ExternalPersonMapper.java
index 658e81c..460485b 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/mapper/ExternalPersonMapper.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/mapper/ExternalPersonMapper.java
@@ -28,6 +28,7 @@
@Mapping( source="contact.uuid", target="contactUuid"),
@Mapping( source="contact.contactType", target="contactType"),
@Mapping( source="contact.note", target="contactNote"),
+ @Mapping( source="contact.anonymized", target="contactAnonymized"),
@Mapping( source="refPersonType.uuid", target="personTypeUuid"),
@Mapping( source="refPersonType.type", target="personType"),
@Mapping( source="salutation.uuid", target="salutationUuid"),
@@ -39,6 +40,7 @@
@Mapping( source="contactUuid", target="contact.uuid"),
@Mapping( source="contactType", target="contact.contactType"),
@Mapping( source="contactNote", target="contact.note"),
+ @Mapping( source="contactAnonymized", target="contact.anonymized"),
@Mapping( source="personTypeUuid", target="refPersonType.uuid"),
@Mapping( source="personType", target="refPersonType.type"),
@Mapping( source="salutationUuid", target="salutation.uuid"),
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/mapper/InternalPersonMapper.java b/src/main/java/org/eclipse/openk/contactbasedata/mapper/InternalPersonMapper.java
index 80069a0..8d57feb 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/mapper/InternalPersonMapper.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/mapper/InternalPersonMapper.java
@@ -29,6 +29,7 @@
@Mapping( source="contact.uuid", target="contactUuid"),
@Mapping( source="contact.contactType", target="contactType"),
@Mapping( source="contact.note", target="contactNote"),
+ @Mapping( source="contact.anonymized", target="contactAnonymized"),
@Mapping( source="refPersonType.uuid", target="personTypeUuid"),
@Mapping( source="refPersonType.type", target="personType"),
@Mapping( source="salutation.uuid", target="salutationUuid"),
@@ -40,6 +41,7 @@
@Mapping( source="contactUuid", target="contact.uuid"),
@Mapping( source="contactType", target="contact.contactType"),
@Mapping( source="contactNote", target="contact.note"),
+ @Mapping( source="contactAnonymized", target="contact.anonymized"),
@Mapping( source="personTypeUuid", target="refPersonType.uuid"),
@Mapping( source="personType", target="refPersonType.type"),
@Mapping( source="salutationUuid", target="salutation.uuid"),
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/RefCommunicationType.java b/src/main/java/org/eclipse/openk/contactbasedata/model/RefCommunicationType.java
index 87aba2c..961727b 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/RefCommunicationType.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/RefCommunicationType.java
@@ -33,6 +33,7 @@
private String description;
private boolean editable;
private boolean mappingLdap;
+ private boolean typeEmail;
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java b/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java
index f5cd6fe..b5ff016 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java
@@ -33,6 +33,7 @@
private UUID uuid;
private String contactType;
private String note;
+ private Boolean anonymized;
@OneToMany(cascade=CascadeType.ALL, mappedBy="tblContact", orphanRemoval = true)
private List<TblAddress> addresses = new ArrayList<>();
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java b/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java
index e514d96..46db683 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java
@@ -17,12 +17,8 @@
import lombok.Data;
import org.springframework.data.annotation.Immutable;
-import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
-import javax.persistence.OneToMany;
-import java.util.ArrayList;
-import java.util.List;
import java.util.UUID;
@Data
@@ -51,5 +47,6 @@
private String community;
private String email;
private String searchfield;
+ private Boolean anonymized;
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java
index a189d08..eedbfa5 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java
@@ -14,7 +14,6 @@
*/
package org.eclipse.openk.contactbasedata.repository;
-import org.eclipse.openk.contactbasedata.model.TblAddress;
import org.eclipse.openk.contactbasedata.model.TblCommunication;
import org.eclipse.openk.contactbasedata.model.TblContact;
import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/CompanyRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/CompanyRepository.java
index b27c86c..efb44aa 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/CompanyRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/CompanyRepository.java
@@ -15,6 +15,8 @@
package org.eclipse.openk.contactbasedata.repository;
import org.eclipse.openk.contactbasedata.model.TblCompany;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
@@ -25,4 +27,6 @@
public interface CompanyRepository extends JpaRepository<TblCompany, Long > {
@Query("select co from TblCompany co where co.contact.uuid = :contactUuid")
Optional<TblCompany> findByTblContactUuid(@Param("contactUuid") UUID contactUuid);
+
+ Page<TblCompany> findByContact_anonymizedFalseOrContact_anonymizedIsNull(Pageable pageable); // NOSONAR fd 07.02.2020: Method name cannot be changed
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactPersonRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactPersonRepository.java
index cdb48e6..d7fd41c 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactPersonRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactPersonRepository.java
@@ -18,6 +18,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
+import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -26,4 +27,5 @@
@Query("select cp from TblContactPerson cp where cp.contact.uuid = ?1")
Optional< TblContactPerson > findByTblContactUuid(final UUID contactUuid);
+ List<TblContactPerson> findByContact_anonymizedFalseOrContact_anonymizedIsNull(); // NOSONAR fd 07.02.2020: Method name cannot be changed
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
index f63d8c1..97351ae 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
@@ -15,7 +15,6 @@
package org.eclipse.openk.contactbasedata.repository;
import org.eclipse.openk.contactbasedata.model.TblContact;
-import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java
index e679c4f..3634bb2 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java
@@ -34,17 +34,24 @@
+ " and (COALESCE(:moduleName) is null or COALESCE(:moduleName) is not null AND dc.fkContactId in (select distinct amc.tblContact.id from TblAssignmentModulContact amc where amc.modulName=:moduleName))"
+ " and (COALESCE(:withoutModule) = false or COALESCE(:withoutModule) = true AND dc.fkContactId not in "
+ " (select distinct amc.tblContact.id from TblAssignmentModulContact amc)) "
- + " and (COALESCE(:dateTimeNow) is null or COALESCE(:dateTimeNow) is not null AND dc.fkContactId in "
+ + " and (COALESCE(:filterExpiringDate) = false or COALESCE(:filterExpiringDate) = true AND dc.fkContactId in "
+ " (select distinct amc.tblContact.id from TblAssignmentModulContact amc where "
+ " amc.expiringDate is not null and amc.expiringDate < :dateTimeNow and "
+ " (amc.deletionLockUntil is null or amc.deletionLockUntil is not null and amc.deletionLockUntil < :dateTimeNow )))"
+ + " and (COALESCE(:filterDelLockExceeded) = false or COALESCE(:filterDelLockExceeded) = true and dc.fkContactId in "
+ + " (select distinct amc.tblContact.id from TblAssignmentModulContact amc where "
+ + " amc.deletionLockUntil is not null and amc.deletionLockUntil < :dateTimeNow ))"
+ + " and (COALESCE(:showAnonymized) = true or COALESCE(:showAnonymized) = false and COALESCE(dc.anonymized, false) = false)"
)
- Page<VwDetailedContact> findByFilter(@Param("contactType")String contactType,
+ Page<VwDetailedContact> findByFilter(@Param("contactType")String contactType, // NOSONAR _fd 07.02.2020 moving to a param object will not increase the readability here!
@Param("personType") UUID personType,
@Param("searchText") String searchText,
@Param("moduleName") String moduleName,
@Param("withoutModule") boolean withoutModule,
@Param("dateTimeNow") Date dateTimeNow,
+ @Param("filterExpiringDate") boolean filterExpiringDate,
+ @Param("filterDelLockExceeded") boolean filterDelLockExceeded,
+ @Param("showAnonymized") boolean showAnonymized,
Pageable pageable);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/ExternalPersonRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/ExternalPersonRepository.java
index b93f36f..68888ba 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/ExternalPersonRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/ExternalPersonRepository.java
@@ -15,8 +15,11 @@
package org.eclipse.openk.contactbasedata.repository;
import org.eclipse.openk.contactbasedata.model.TblExternalPerson;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
+
import java.util.Optional;
import java.util.UUID;
@@ -24,4 +27,6 @@
@Query("select ep from TblExternalPerson ep where ep.contact.uuid = ?1")
Optional< TblExternalPerson > findByTblContactUuid(final UUID contactUuid );
+ Page<TblExternalPerson> findByContact_anonymizedFalseOrContact_anonymizedIsNull(Pageable pageable); // NOSONAR fd 07.02.2020: Method name cannot be changed
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/InternalPersonRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/InternalPersonRepository.java
index 29c780d..22348d0 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/InternalPersonRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/InternalPersonRepository.java
@@ -35,4 +35,6 @@
@Param( "userRef") String userRef,
Pageable pageable);
+ Page<TblInternalPerson> findByContact_anonymizedFalseOrContact_anonymizedIsNull(Pageable pageable); // NOSONAR fd 07.02.2020: Method name cannot be changed
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java
index 54790a6..f06ce72 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java
@@ -15,6 +15,7 @@
package org.eclipse.openk.contactbasedata.service;
import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
import org.eclipse.openk.contactbasedata.enums.OperationType;
import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
@@ -29,6 +30,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -59,7 +61,7 @@
public AddressDto getAddress(UUID contactUuid, UUID addressUuid){
TblAddress tblAddress = addressRepository.findByUuid(addressUuid)
- .orElseThrow( () -> new NotFoundException("address.uuid.not.existing"));
+ .orElseThrow( () -> new NotFoundException(Constants.ADDRESS_UUID_NOT_EXISTING));
if(!tblAddress.getTblContact().getUuid().equals(contactUuid)) {
throw new BadRequestException("invalid.uuid.path.object");
}
@@ -71,7 +73,7 @@
TblContact tblContact = contactRepository
.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
TblAddress addressToSave = addressMapper.toTblAddress(addressDto);
addressToSave.setUuid(UUID.randomUUID());
@@ -91,10 +93,10 @@
public AddressDto updateAddress(UUID contactUuid, AddressDto addressDto) {
TblContact contact = contactRepository.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
TblAddress address = addressRepository.findByUuid(addressDto.getUuid())
- .orElseThrow(() -> new NotFoundException("address.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.ADDRESS_UUID_NOT_EXISTING));
TblAddress addressToSave = addressMapper.toTblAddress(addressDto);
addressToSave.setTblContact(contact);
@@ -109,13 +111,12 @@
return addressMapper.toAddressDto(savedAddress);
}
-
@Transactional
public void deleteAddress(UUID contactUuid, UUID addressUuid) {
TblContact tblContact = contactRepository.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
TblAddress tblAddress = addressRepository.findByTblContactAndUuid(tblContact, addressUuid)
- .orElseThrow(() -> new NotFoundException("address.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.ADDRESS_UUID_NOT_EXISTING));
addressRepository.delete(tblAddress);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java
index bd5ce40..f76429d 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java
@@ -29,6 +29,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.time.Instant;
+import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -73,6 +75,7 @@
TblAssignmentModulContact assignmentToSave = assignmentModulContactMapper.toTblAssignmentModulContact(assignmentDto);
assignmentToSave.setUuid(UUID.randomUUID());
assignmentToSave.setTblContact(tblContact);
+ assignmentToSave.setAssignmentDate(Date.from(Instant.now()));
if ( !checkUniqueAssignmentForContactAndModuleForInsert(tblContact.getId(), assignmentDto.getModulName())) {
throw new OperationDeniedException(OperationType.INSERT, "assignment.already.existing");
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java
index 1b771ee..a824509 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java
@@ -15,18 +15,18 @@
package org.eclipse.openk.contactbasedata.service;
import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
import org.eclipse.openk.contactbasedata.enums.OperationType;
import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
import org.eclipse.openk.contactbasedata.exceptions.OperationDeniedException;
-import org.eclipse.openk.contactbasedata.mapper.AddressMapper;
import org.eclipse.openk.contactbasedata.mapper.CommunicationMapper;
import org.eclipse.openk.contactbasedata.model.RefCommunicationType;
-import org.eclipse.openk.contactbasedata.model.TblAddress;
import org.eclipse.openk.contactbasedata.model.TblCommunication;
import org.eclipse.openk.contactbasedata.model.TblContact;
-import org.eclipse.openk.contactbasedata.repository.*;
-import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.repository.CommunicationRepository;
+import org.eclipse.openk.contactbasedata.repository.CommunicationTypeRepository;
+import org.eclipse.openk.contactbasedata.repository.ContactRepository;
import org.eclipse.openk.contactbasedata.viewmodel.CommunicationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -62,7 +62,7 @@
public CommunicationDto getCommunication(UUID contactUuid, UUID communicationUuid){
TblCommunication tblCommunication = communicationRepository.findByUuid(communicationUuid)
- .orElseThrow( () -> new NotFoundException("communication.uuid.not.existing"));
+ .orElseThrow( () -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
if(!tblCommunication.getTblContact().getUuid().equals(contactUuid)) {
throw new BadRequestException("invalid.uuid.path.object");
}
@@ -74,11 +74,11 @@
TblContact tblContact = contactRepository
.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
RefCommunicationType refCommunicationType = communicationTypeRepository
.findByUuid(communicationDto.getCommunicationTypeUuid())
- .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
TblCommunication communicationToSave = communicationMapper.toTblCommunication(communicationDto);
@@ -87,7 +87,7 @@
communicationToSave.setRefCommunicationType(refCommunicationType);
if ( !checkUniqueCommunicationTypeForContactForInsert(tblContact.getId(), refCommunicationType.getId())) {
- throw new OperationDeniedException(OperationType.INSERT, "communication.type.already.existing.for.contact");
+ throw new OperationDeniedException(OperationType.INSERT, Constants.COMMUNICATION_TYPE_ALREADY_EXISTING_FOR_CONTACT);
}
setFromCommunicationDto(communicationToSave, communicationDto);
@@ -100,14 +100,14 @@
public CommunicationDto updateCommunication(UUID contactUuid, CommunicationDto communicationDto) {
TblContact contact = contactRepository.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
TblCommunication communication = communicationRepository.findByUuid(communicationDto.getUuid())
- .orElseThrow(() -> new NotFoundException("communication.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
RefCommunicationType refCommunicationType = communicationTypeRepository
.findByUuid(communicationDto.getCommunicationTypeUuid())
- .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_TYPE_UUID_NOT_EXISTING));
TblCommunication communicationToSave = communicationMapper.toTblCommunication(communicationDto);
communicationToSave.setTblContact(contact);
@@ -115,7 +115,7 @@
communicationToSave.setId(communication.getId());
if ( !checkUniqueCommunicationTypeForContactForUpdate(contact.getId(), refCommunicationType.getId(), communication.getUuid())) {
- throw new OperationDeniedException(OperationType.UPDATE, "communication.type.already.existing.for.contact");
+ throw new OperationDeniedException(OperationType.UPDATE, Constants.COMMUNICATION_TYPE_ALREADY_EXISTING_FOR_CONTACT);
}
setFromCommunicationDto(communicationToSave, communicationDto);
@@ -127,9 +127,9 @@
@Transactional
public void deleteCommunication(UUID contactUuid, UUID communicationUuid) {
TblContact tblContact = contactRepository.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
TblCommunication tblCommunication = communicationRepository.findByTblContactAndUuid(tblContact, communicationUuid)
- .orElseThrow(() -> new NotFoundException("communication.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
communicationRepository.delete(tblCommunication);
}
@@ -148,7 +148,7 @@
if( sourceDto.getCommunicationTypeUuid() != null ) {
destTblCommunication.setRefCommunicationType( communicationTypeRepository
.findByUuid(sourceDto.getCommunicationTypeUuid())
- .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing")));
+ .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_TYPE_UUID_NOT_EXISTING)));
}
else {
destTblCommunication.setRefCommunicationType(null);
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java
index b1f9730..e38a7b6 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java
@@ -17,11 +17,13 @@
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
import org.eclipse.openk.contactbasedata.mapper.CommunicationTypeMapper;
-import org.eclipse.openk.contactbasedata.model.*;
-import org.eclipse.openk.contactbasedata.repository.*;
+import org.eclipse.openk.contactbasedata.model.RefCommunicationType;
+import org.eclipse.openk.contactbasedata.repository.CommunicationTypeRepository;
import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -48,6 +50,7 @@
.collect(Collectors.toList());
}
+ @Transactional
public CommunicationTypeDto insertCommunicationType(CommunicationTypeDto communicationTypeDto) {
RefCommunicationType communicationTypeToSave = communicationTypeMapper.toRefCommunicationType(communicationTypeDto);
@@ -58,7 +61,7 @@
return communicationTypeMapper.toCommunicationTypeDto(savedCommunicationType);
}
-
+ @Transactional
public CommunicationTypeDto updateCommunicationType(CommunicationTypeDto communicationTypeDto){
RefCommunicationType communicationTypeUpdated;
@@ -74,7 +77,7 @@
return communicationTypeMapper.toCommunicationTypeDto(communicationTypeUpdated);
}
-
+ @Transactional
public void removeCommunicationType(UUID uuid) {
RefCommunicationType existingCommunicationType = communicationTypeRepository.findByUuid(uuid)
.orElseThrow( () -> new NotFoundException("communication.type.uuid.not.existing"));
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java
index 9957faf..1f76b0e 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java
@@ -74,8 +74,12 @@
);
}
- public Page<CompanyDto> findCompanies(Pageable pageable) {
- return companyRepository.findAll(pageable).map(companyMapper::toCompanyDto);
+ public Page<CompanyDto> findCompanies(Boolean showAlsoAnonymous, Pageable pageable) {
+ return (Boolean.TRUE.equals(showAlsoAnonymous)
+ ? companyRepository.findAll(pageable)
+ : companyRepository.findByContact_anonymizedFalseOrContact_anonymizedIsNull(pageable))
+ .map(companyMapper::toCompanyDto);
+
}
@@ -113,10 +117,16 @@
return companyMapper.toCompanyDto(companyUpdated);
}
- public List<ContactPersonDto> findContactPersonsToCompany( UUID companyContactUuid ) {
+ public List<ContactPersonDto> findContactPersonsToCompany(UUID companyContactUuid, boolean alsoShowAnonymous) {
TblCompany company = companyRepository.findByTblContactUuid( companyContactUuid )
.orElseThrow( NotFoundException::new);
List<TblContactPerson> tblContactPeople = company.getContactPersons();
+
+ if( !alsoShowAnonymous ) {
+ tblContactPeople = tblContactPeople.stream().filter( cp -> cp.getContact().getAnonymized() == null
+ || !cp.getContact().getAnonymized() )
+ .collect(Collectors.toList());
+ }
Map<UUID, TblContactPerson> tblContactPersonMap = tblContactPeople.stream()
.collect( Collectors.toMap(cp -> cp.getContact().getUuid(), x -> x));
@@ -134,14 +144,15 @@
// TODO: Move to Mapper
TblCommunication tblComm = cpMap.get(dto.getContactUuid()).getContact()
.getCommunications().stream()
- .filter(comm -> comm.getRefCommunicationType().getId() == 1L)
+ .filter(comm -> comm.getRefCommunicationType().isTypeEmail())
.findFirst().orElse(null);
-// TODO: exchange constant 1L with DB-Solution
+
dto.setEmail( tblComm == null ? "" : tblComm.getCommunicationData() );
}
private void setFromCompanyDto( TblCompany destTblCompany, CompanyDto sourceDto ) {
destTblCompany.getContact().setNote(sourceDto.getContactNote());
+ destTblCompany.getContact().setAnonymized(sourceDto.getContactAnonymized());
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactAnonymizerService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactAnonymizerService.java
new file mode 100644
index 0000000..45feaa4
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactAnonymizerService.java
@@ -0,0 +1,177 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.contactbasedata.service;
+
+import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
+import org.eclipse.openk.contactbasedata.exceptions.InternalServerErrorException;
+import org.eclipse.openk.contactbasedata.model.TblContact;
+import org.eclipse.openk.contactbasedata.viewmodel.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.util.Date;
+import java.util.UUID;
+
+@Log4j2
+@Service
+public class ContactAnonymizerService {
+ @Autowired
+ ContactService contactService;
+
+ @Autowired
+ private CompanyService companyService;
+
+ @Autowired
+ private ExternalPersonService externalPersonService;
+
+ @Autowired
+ private InternalPersonService internalPersonService;
+
+ @Autowired
+ private ContactPersonService contactPersonService;
+
+ @Autowired
+ private AddressService addressService;
+
+ @Autowired
+ private CommunicationService communicationService;
+
+ @Transactional
+ public void anonymize( UUID contactUuid ) {
+ TblContact tblContact = contactService.findTblContact(contactUuid);
+
+ switch( tblContact.getContactType() ) {
+ case Constants.CONTACT_TYPE_COMPANY:
+ anonymizeCompany( tblContact.getUuid() );
+ break;
+ case Constants.CONTACT_TYPE_INTERNAL_PERSON:
+ anonymizeInternalPerson( tblContact.getUuid() );
+ break;
+ case Constants.CONTACT_TYPE_EXTERNAL_PERSON:
+ anonymizeExternalPerson( tblContact.getUuid() );
+ break;
+ case Constants.CONTACT_TYPE_CONTACT_PERSON:
+ anonymizeContactPerson( tblContact.getUuid() );
+ break;
+ default:
+ log.warn("Invalid Contact Type: "+tblContact.getContactType()+"for contact: "+contactUuid);
+ throw new InternalServerErrorException("Invalid contact type found");
+ }
+ }
+
+ private void anonymizeCompany( UUID contactUuid ) {
+ CompanyDto dto = companyService.findCompany(contactUuid);
+ dto.setCompanyName(Constants.ANONYMOUS_TAG);
+ dto.setCompanyType(null);
+ dto.setContactNote(getContactNote());
+ dto.setContactAnonymized(true);
+ companyService.updateCompany(dto);
+
+ // kill 'em all
+ companyService.findContactPersonsToCompany(contactUuid, false).stream()
+ .forEach(contactPersonDto -> anonymizeContactPerson(contactPersonDto.getContactUuid()));
+
+ processDependencies(contactUuid);
+ }
+
+ private void anonymizeInternalPerson( UUID contactUuid ) {
+ InternalPersonDto internalPersonDto = internalPersonService.findInternalPerson(contactUuid);
+ internalPersonDto.setLastName(Constants.ANONYMOUS_TAG);
+ internalPersonDto.setFirstName(null);
+ internalPersonDto.setTitle(null);
+ internalPersonDto.setDepartment(null);
+ internalPersonDto.setUid(null);
+ internalPersonDto.setUserRef(null);
+ internalPersonDto.setSalutationUuid(null);
+ internalPersonDto.setContactNote(getContactNote());
+ internalPersonDto.setContactAnonymized(true);
+
+ internalPersonService.updateInternalPerson(internalPersonDto);
+
+ processDependencies(contactUuid);
+ }
+
+ private void anonymizeExternalPerson( UUID contactUuid ) {
+ ExternalPersonDto externalPersonDto = externalPersonService.findExternalPerson(contactUuid);
+ externalPersonDto.setLastName(Constants.ANONYMOUS_TAG);
+ externalPersonDto.setFirstName(null);
+ externalPersonDto.setTitle(null);
+ // leave personType untouched
+ externalPersonDto.setSalutationUuid(null);
+ externalPersonDto.setContactNote(getContactNote());
+ externalPersonDto.setContactAnonymized(true);
+ externalPersonService.updateExternalPerson(externalPersonDto);
+
+ processDependencies(contactUuid);
+ }
+
+ private void anonymizeContactPerson( UUID contactUuid ) {
+ ContactPersonDto contactPersonDto = contactPersonService.findContactPerson(contactUuid);
+ contactPersonDto.setLastName(Constants.ANONYMOUS_TAG);
+ contactPersonDto.setFirstName(null);
+ contactPersonDto.setTitle(null);
+ // leave personType untouched
+ contactPersonDto.setSalutationUuid(null);
+ contactPersonDto.setContactNote(getContactNote());
+ contactPersonDto.setContactAnonymized(true);
+ contactPersonService.updateContactPerson(contactPersonDto);
+
+ processDependencies(contactUuid);
+ }
+
+ private void processDependencies(UUID contactUuid) {
+ addressService.getAddressesByContactUuid(contactUuid).stream()
+ .forEach(this::anonymizeAddress);
+
+ communicationService.getCommunicationsByContactUuid(contactUuid).stream()
+ .forEach(this::anonymizeCommunication);
+ }
+
+ private void anonymizeAddress( AddressDto addressDto ) {
+ addressDto.setCommunity(Constants.ANONYMOUS_TAG);
+ addressDto.setStreet(Constants.ANONYMOUS_TAG);
+ addressDto.setCommunitySuffix(null);
+ addressDto.setHousenumber(null);
+ addressDto.setLatitude(null);
+ addressDto.setLongitude(null);
+ addressDto.setNote(null);
+ addressDto.setPostcode(null);
+ addressDto.setUrlMap(null);
+ addressDto.setNote(Constants.ANONYMOUS_TAG);
+
+ addressService.updateAddress(addressDto.getContactUuid(), addressDto);
+ }
+
+ private void anonymizeCommunication(CommunicationDto communicationDto ) {
+ communicationDto.setCommunicationData(Constants.ANONYMOUS_TAG);
+ communicationDto.setCommunicationTypeDescription(null);
+ communicationDto.setNote(Constants.ANONYMOUS_TAG);
+
+ communicationService.updateCommunication(communicationDto.getContactUuid(), communicationDto);
+ }
+
+ private static String getContactNote() {
+ return new StringBuilder()
+ .append("*** [")
+ .append(new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(Date.from(Instant.now())))
+ .append("] ***")
+ .toString();
+ }
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java
index e2bef26..05adbda 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java
@@ -114,9 +114,9 @@
private ContactPersonDto setFromTblContactPerson( ContactPersonDto destDto, TblContactPerson srcTblContactPerson ) {
TblCommunication tblComm = srcTblContactPerson.getContact()
.getCommunications().stream()
- .filter(comm -> comm.getRefCommunicationType().getId() == 1L)
+ .filter(comm -> comm.getRefCommunicationType().isTypeEmail())
.findFirst().orElse(null);
-// TODO: exchange constant 1L with DB-Solution
+
// TODO: Move to Mapper
destDto.setEmail(tblComm != null ? tblComm.getCommunicationData() : null );
@@ -153,5 +153,6 @@
}
destTblContactPerson.getContact().setNote(sourceDto.getContactNote());
+ destTblContactPerson.getContact().setAnonymized(sourceDto.getContactAnonymized());
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java
index 4dbe779..aa50605 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java
@@ -15,10 +15,14 @@
package org.eclipse.openk.contactbasedata.service;
import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
+import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
import org.eclipse.openk.contactbasedata.mapper.ContactMapper;
+import org.eclipse.openk.contactbasedata.model.TblContact;
import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
import org.eclipse.openk.contactbasedata.repository.ContactRepository;
import org.eclipse.openk.contactbasedata.repository.DetailedContactRepository;
+import org.eclipse.openk.contactbasedata.service.util.SearchContactsFilterParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -38,31 +42,24 @@
@Autowired
private ContactMapper contactMapper;
- public Page<VwDetailedContact> findDetailedContacts(String contactType,
- UUID personTypeUuid,
- String searchText,
- String moduleName,
- boolean withoutModule,
- boolean expiringDataInPast,
- Pageable pageable) {
+ public TblContact findTblContact(UUID contactUuid ) {
+ return contactRepository.findByUuid( contactUuid ).orElseThrow( () -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
+ }
- if( contactType == null &&
- personTypeUuid == null &&
- searchText == null &&
- moduleName == null &&
- !withoutModule &&
- !expiringDataInPast ) {
- return detailedContactRepository.findAll(pageable);
- }
- else {
- return detailedContactRepository.findByFilter( contactType,
- personTypeUuid,
- searchText != null ? searchText.toUpperCase() : null,
- moduleName,
- withoutModule,
- expiringDataInPast ? Date.from(Instant.now()) : null,
+ public Page<VwDetailedContact> findDetailedContacts(
+ SearchContactsFilterParams searchContactsFilterParams,
+ Pageable pageable) {
+ return detailedContactRepository.findByFilter(
+ searchContactsFilterParams.getContactType(),
+ searchContactsFilterParams.getPersonTypeUuid(),
+ searchContactsFilterParams.getSearchText() != null ? searchContactsFilterParams.getSearchText().toUpperCase() : null,
+ searchContactsFilterParams.getModuleName(),
+ searchContactsFilterParams.isWithoutModule(),
+ Date.from(Instant.now()),
+ searchContactsFilterParams.isExpiringDataInPast(),
+ searchContactsFilterParams.isDelLockExceeded(),
+ searchContactsFilterParams.isShowAnonymized(),
pageable);
- }
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/ExternalPersonService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/ExternalPersonService.java
index daf04e4..653cb80 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/ExternalPersonService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ExternalPersonService.java
@@ -64,8 +64,11 @@
);
}
- public Page<ExternalPersonDto> findExternalPersons(Pageable pageable) {
- return externalPersonRepository.findAll(pageable).map(externalPersonMapper::toExternalPersonDto);
+ public Page<ExternalPersonDto> findExternalPersons(boolean showAlsoAnonymous, Pageable pageable) {
+ return (showAlsoAnonymous
+ ? externalPersonRepository.findAll(pageable)
+ : externalPersonRepository.findByContact_anonymizedFalseOrContact_anonymizedIsNull(pageable))
+ .map(externalPersonMapper::toExternalPersonDto);
}
@@ -124,5 +127,6 @@
}
destTblExternalPerson.getContact().setNote(sourceDto.getContactNote());
+ destTblExternalPerson.getContact().setAnonymized(sourceDto.getContactAnonymized());
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/InternalPersonService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/InternalPersonService.java
index c10b9d6..6cf8c54 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/InternalPersonService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/InternalPersonService.java
@@ -64,10 +64,12 @@
);
}
- public Page<InternalPersonDto> findInternalPersons(String uid, String userRef, Pageable pageable) {
+ public Page<InternalPersonDto> findInternalPersons( boolean showAlsoAnonymous, String uid, String userRef, Pageable pageable) {
Page<TblInternalPerson> returnPageDb;
if( uid == null && userRef == null) {
- returnPageDb = internalPersonRepository.findAll( pageable );
+ returnPageDb = showAlsoAnonymous ?
+ internalPersonRepository.findAll( pageable )
+ : internalPersonRepository.findByContact_anonymizedFalseOrContact_anonymizedIsNull(pageable);
}
else {
returnPageDb = internalPersonRepository.findByFilter( uid, userRef, pageable );
@@ -135,5 +137,6 @@
}
destTblInternalPerson.getContact().setNote(sourceDto.getContactNote());
+ destTblInternalPerson.getContact().setAnonymized(sourceDto.getContactAnonymized());
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
index 9c615d0..6c12c80 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
@@ -15,6 +15,7 @@
package org.eclipse.openk.contactbasedata.service;
import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
import org.eclipse.openk.contactbasedata.mapper.SalutationMapper;
@@ -48,7 +49,7 @@
public SalutationDto getSalutationByUuid(UUID salutationUuid) {
RefSalutation refSalutation = salutationRepository
.findByUuid(salutationUuid)
- .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.SALUTATION_UUID_NOT_EXISTING));
return salutationMapper.toSalutationDto(refSalutation);
}
@@ -67,7 +68,7 @@
RefSalutation salutationToSave = salutationMapper.toRefSalutation(salutationDto);
RefSalutation existingSalutation = salutationRepository
.findByUuid(salutationDto.getUuid())
- .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.SALUTATION_UUID_NOT_EXISTING));
salutationToSave.setId(existingSalutation.getId());
salutationUpdated = salutationRepository.save(salutationToSave);
@@ -77,7 +78,7 @@
@Transactional
public void removeSalutation(UUID uuid) {
RefSalutation existingSalutation = salutationRepository.findByUuid(uuid)
- .orElseThrow( () -> new BadRequestException("salutation.uuid.not.existing"));
+ .orElseThrow( () -> new BadRequestException(Constants.SALUTATION_UUID_NOT_EXISTING));
salutationRepository.delete(existingSalutation);
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java b/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java
new file mode 100644
index 0000000..a62ffe3
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java
@@ -0,0 +1,33 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.contactbasedata.service.util;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.UUID;
+
+@Data
+@NoArgsConstructor
+public class SearchContactsFilterParams {
+ private String contactType; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private UUID personTypeUuid; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private String searchText; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private String moduleName; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private boolean withoutModule; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private boolean expiringDataInPast; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private boolean delLockExceeded; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+ private boolean showAnonymized; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CommunicationTypeDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CommunicationTypeDto.java
index 7b8c083..20926b6 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CommunicationTypeDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CommunicationTypeDto.java
@@ -35,4 +35,5 @@
private String description;
private boolean editable;
private boolean mappingLdap;
+ private boolean typeEmail;
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CompanyDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CompanyDto.java
index ff000d3..183dc75 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CompanyDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CompanyDto.java
@@ -36,4 +36,5 @@
private UUID contactUuid;
private String contactType;
private String contactNote;
+ private Boolean contactAnonymized;
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactDto.java
index b852ff9..27322c0 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactDto.java
@@ -27,5 +27,7 @@
private UUID uuid;
private String contactType;
private String note;
+ private Boolean anonymized;
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactPersonDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactPersonDto.java
index 2e6f162..db0275c 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactPersonDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ContactPersonDto.java
@@ -38,6 +38,8 @@
private UUID contactUuid;
private String contactType;
private String contactNote;
+ private Boolean contactAnonymized;
+
//from Company
@JsonProperty("companyContactId")
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ExternalPersonDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ExternalPersonDto.java
index 6720bc7..5e8cd90 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ExternalPersonDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/ExternalPersonDto.java
@@ -38,6 +38,7 @@
private UUID contactUuid;
private String contactType;
private String contactNote;
+ private Boolean contactAnonymized;
// from RefPersonType
@JsonProperty("personTypeId")
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/InternalPersonDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/InternalPersonDto.java
index 5325aca..27969b2 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/InternalPersonDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/InternalPersonDto.java
@@ -40,6 +40,7 @@
private UUID contactUuid;
private String contactType;
private String contactNote;
+ private Boolean contactAnonymized;
// from RefPersonType
@JsonProperty("personTypeId")
diff --git a/src/main/resources/db/migration/V0_13__CREATE_CBD_DB.sql b/src/main/resources/db/migration/V0_13__CREATE_CBD_DB.sql
new file mode 100644
index 0000000..6406c0c
--- /dev/null
+++ b/src/main/resources/db/migration/V0_13__CREATE_CBD_DB.sql
@@ -0,0 +1,694 @@
+-----------------------------------------------------------------------------------
+-- *******************************************************************************
+-- * Copyright (c) 2019 Contributors to the Eclipse Foundation
+-- *
+-- * See the NOTICE file(s) distributed with this work for additional
+-- * information regarding copyright ownership.
+-- *
+-- * This program and the accompanying materials are made available under the
+-- * terms of the Eclipse Public License v. 2.0 which is available at
+-- * http://www.eclipse.org/legal/epl-2.0.
+-- *
+-- * SPDX-License-Identifier: EPL-2.0
+-- *******************************************************************************
+-----------------------------------------------------------------------------------
+
+-- CREATE ROLE CBD_SERVICE LOGIN
+-- NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
+-- ALTER ROLE CBD_SERVICE with password 'cbd_service';
+-- Insert new Columns into table REF_COMMUNICATION_TYPE ('EDITABLE, 'MAPPING_LDAP')
+
+-- ---------------------------------------------
+-- DROPS
+-- ---------------------------------------------
+DROP TABLE IF EXISTS public.VERSION CASCADE;
+
+DROP TABLE IF EXISTS public.TBL_ADDRESS CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_ADDRESS_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_COMMUNICATION CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_COMMUNICATION_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_CONTACT_PERSON CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_CONTACT_PERSON_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_COMPANY CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_COMPANY_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_EXTERNAL_PERSON CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_EXTERNAL_PERSON_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_INTERNAL_PERSON CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_INTERNAL_PERSON_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_CONTACT CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_CONTACT_ID_SEQ;
+
+DROP TABLE IF EXISTS public.REF_ADDRESS_TYPE CASCADE;
+DROP SEQUENCE IF EXISTS public.REF_ADDRESS_TYPE_ID_SEQ;
+
+DROP TABLE IF EXISTS public.REF_PERSON_TYPE CASCADE;
+DROP SEQUENCE IF EXISTS public.REF_PERSON_TYPE_ID_SEQ;
+
+DROP TABLE IF EXISTS public.REF_COMMUNICATION_TYPE CASCADE;
+DROP SEQUENCE IF EXISTS public.REF_COMMUNICATION_TYPE_ID_SEQ;
+
+DROP TABLE IF EXISTS public.REF_SALUTATION CASCADE;
+DROP SEQUENCE IF EXISTS public.REF_SALUTATION_ID_SEQ;
+
+DROP TABLE IF EXISTS public.TBL_ASSIGNMENT_MODUL_CONTACT CASCADE;
+DROP SEQUENCE IF EXISTS public.TBL_ASSIGNMENT_MODUL_CONTACT_ID_SEQ;
+
+-- ---------------------------------------------
+-- TABLE VERSION
+-- ---------------------------------------------
+CREATE TABLE public.VERSION
+(
+ ID integer NOT NULL,
+ VERSION character varying(50) NOT NULL,
+ CONSTRAINT REF_VERSION_PKEY PRIMARY KEY (id)
+);
+
+ALTER TABLE public.VERSION
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.VERSION TO CBD_SERVICE;
+
+INSERT INTO public.VERSION (ID, VERSION) VALUES ( 1, '00-DEV' );
+
+
+-- ---------------------------------------------
+-- TABLE TBL_CONTACT
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_contact_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_contact_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.TBL_CONTACT
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_contact_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ CONTACT_TYPE character varying(3),
+ NOTE character varying(255),
+ ANONYMIZED boolean,
+ CONSTRAINT TBL_CONTACT_PKEY PRIMARY KEY (ID)
+);
+
+
+
+ALTER TABLE public.TBL_CONTACT
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_CONTACT TO CBD_SERVICE;
+
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( 'ae3f2ec1-ccc5-4269-a48f-dd40e37fa14e', 'COM', 'company 1 (id=1)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( 'fc7f598b-0d51-46bb-9563-99851fe6a3ad', 'COM', 'company 2 (id=2)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '556b91be-6d57-432f-93ed-65604dd6e5cd', 'C_P', 'contact person 1 (id=3)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '116380e3-25c5-4179-b40a-8abebe10fe07', 'C_P', 'contact person 2 (id=4)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '7782179b-fb79-4370-8f71-f4c71470d006', 'I_P', 'internal person 1 (id=5)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '8963aa38-d021-4dc9-bd70-d3734ccd20c4', 'I_P', 'internal person 2 (id=6)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( 'c862d604-5766-43d6-a7e8-a4bac2bd01e1', 'E_P', 'external person 1 (id=7)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( 'fa3d981b-a7d6-4965-a623-cdbc69404153', 'E_P', 'external person 2 (id=8)', null );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( 'ceba21e9-e685-483b-840e-ad167860a696', 'COM', 'anonymous company A (id=9)', true );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '7889c814-9752-4e4e-a9fe-b46f36a38ccd', 'COM', 'anonymous company B (id=10)', true );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '618a01a3-f348-44cc-9ddd-c9df946b0212', 'C_P', 'anoymous contact person A1 (id=11)', true );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE, ANONYMIZED) VALUES ( '4ed82474-3878-457a-baef-c28b8e486f25', 'C_P', 'anoymous contact persion A2 (id=12)', true );
+
+
+CREATE UNIQUE INDEX idx_tbl_contact_contact_type ON public.TBL_CONTACT ( ID ASC );
+CREATE UNIQUE INDEX idx_cntct_uuid ON public.TBL_CONTACT (UUID);
+CREATE INDEX idx_cntct_anonym ON public.TBL_CONTACT (ANONYMIZED);
+
+
+-- ---------------------------------------------
+-- TABLE REF_ADDRESS_TYPE
+-- ---------------------------------------------
+CREATE SEQUENCE public.ref_address_type_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.ref_address_type_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.REF_ADDRESS_TYPE
+(
+ ID bigint NOT NULL DEFAULT nextval('ref_address_type_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ TYPE character varying(30),
+ DESCRIPTION character varying(255),
+ CONSTRAINT REF_ADDRESS_TYPE_PKEY PRIMARY KEY (ID)
+);
+
+ALTER TABLE public.REF_ADDRESS_TYPE
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.REF_ADDRESS_TYPE TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_ref_address_type_uuid ON public.REF_ADDRESS_TYPE ( UUID ASC );
+
+INSERT INTO public.REF_ADDRESS_TYPE (UUID, TYPE, DESCRIPTION) VALUES ( '3802e681-9396-434e-b19c-5fedcec40ba7', 'Geschäftsadresse', 'Adresse des Hauptfirmensitzes' );
+INSERT INTO public.REF_ADDRESS_TYPE (UUID, TYPE, DESCRIPTION) VALUES ( 'f43ed6ac-9e7a-40f6-acc9-ec6b73eebf79', 'Privatadresse', 'private Anschrift' );
+INSERT INTO public.REF_ADDRESS_TYPE (UUID, TYPE, DESCRIPTION) VALUES ( '70fd0811-f674-4f3a-96a7-7ae29fc95188', 'Lieferadresse', 'Adresse für Lieferungen' );
+
+
+-- ---------------------------------------------
+-- TABLE REF_PERSON_TYPE
+-- ---------------------------------------------
+CREATE SEQUENCE public.ref_person_type_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.ref_person_type_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.REF_PERSON_TYPE
+(
+ ID bigint NOT NULL DEFAULT nextval('ref_person_type_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ TYPE character varying(30),
+ DESCRIPTION character varying(255),
+ CONSTRAINT REF_PERSON_TYPE_PKEY PRIMARY KEY (ID)
+);
+ALTER TABLE public.REF_PERSON_TYPE
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.REF_PERSON_TYPE TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_ref_person_type_uuid ON public.REF_PERSON_TYPE ( UUID ASC );
+
+INSERT INTO public.REF_PERSON_TYPE (UUID, TYPE, DESCRIPTION) VALUES ( '47ce68b7-6d44-453e-b421-19020fd791b5', 'Rechtsanwalt', '' );
+INSERT INTO public.REF_PERSON_TYPE (UUID, TYPE, DESCRIPTION) VALUES ( 'a7522c72-14d0-4e9d-afe3-bfcb3ffbec10', 'Geschäftsführer', '' );
+INSERT INTO public.REF_PERSON_TYPE (UUID, TYPE, DESCRIPTION) VALUES ( '2eb4885e-7363-4918-90ed-b7d5d84cfd3f', 'Rechnungsempfänger', 'Person, der Rechnungen zukommen' );
+
+
+-- ---------------------------------------------
+-- TABLE REF_COMMUNICATION_TYPE
+-- ---------------------------------------------
+CREATE SEQUENCE public.ref_communication_type_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.ref_communication_type_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.REF_COMMUNICATION_TYPE
+(
+ ID bigint NOT NULL DEFAULT nextval('ref_communication_type_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ TYPE character varying(30),
+ DESCRIPTION character varying(255),
+ EDITABLE boolean,
+ MAPPING_LDAP boolean,
+ TYPE_EMAIL boolean,
+ CONSTRAINT REF_COMMUNICATION_TYPE_PKEY PRIMARY KEY (ID)
+);
+ALTER TABLE public.REF_COMMUNICATION_TYPE
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.REF_COMMUNICATION_TYPE TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_ref_communication_type_uuid ON public.REF_COMMUNICATION_TYPE ( UUID ASC );
+
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP, TYPE_EMAIL) VALUES ( '4757ca3a-72c2-4f13-a2f6-ce092e3eadf4', 'E-Mail', 'E-Mail Adresse', false, true, true );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP, TYPE_EMAIL) VALUES ( '77028572-ff57-4c1d-999a-78fa3fcbc1cd', 'Mobil', '', false, true, false );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP, TYPE_EMAIL) VALUES ( 'f7d5b343-00c2-4d7f-8e03-009aad3d90f7', 'Festnetz', '', true, false, false );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP, TYPE_EMAIL) VALUES ( '2bfe40f9-c4eb-4d2e-855f-6b0883912846', 'Fax', '', true, false, false );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP, TYPE_EMAIL) VALUES ( 'd00d1a61-c8e7-43b2-959f-66e986731441', 'WhatsApp', '', true, false, false );
+
+-- ---------------------------------------------
+-- TABLE REF_SALUTATION
+-- ---------------------------------------------
+CREATE SEQUENCE public.ref_salutation_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.ref_salutation_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.REF_SALUTATION
+(
+ ID bigint NOT NULL DEFAULT nextval('ref_salutation_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ TYPE character varying(30),
+ DESCRIPTION character varying(255),
+ CONSTRAINT REF_SALUTATION_PKEY PRIMARY KEY (ID)
+);
+ALTER TABLE public.REF_SALUTATION
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.REF_SALUTATION TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_ref_salutation_uuid ON public.REF_SALUTATION ( UUID ASC );
+
+INSERT INTO public.REF_SALUTATION (UUID, TYPE, DESCRIPTION) VALUES ( '90119f18-5562-425d-9a36-3dd58ea125e5', 'Herr', 'Anrede männlich' );
+INSERT INTO public.REF_SALUTATION (UUID, TYPE, DESCRIPTION) VALUES ( '4e873baa-e4f5-4585-8b16-2db8fac66538', 'Frau', 'Anrede weiblich' );
+
+
+-- ---------------------------------------------
+-- TABLE TBL_ADDRESS
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_address_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_address_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.TBL_ADDRESS
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_address_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ FK_CONTACT_ID bigint NOT NULL,
+ FK_ADDRESS_TYPE bigint,
+ IS_MAIN_ADDRESS boolean,
+ POSTCODE character varying(30),
+ COMMUNITY character varying(255),
+ COMMUNITY_SUFFIX character varying(255),
+ STREET character varying(255),
+ HOUSENUMBER character varying(30),
+ WGS_84_ZONE character varying(255),
+ LATITUDE character varying(255),
+ LONGITUDE character varying(255),
+ URL_MAP character varying(255),
+ NOTE character varying(255),
+
+ CONSTRAINT TBL_ADDRESS_PKEY PRIMARY KEY (ID),
+ CONSTRAINT TBL_ADDRESS__CONTACT_ID_FKEY FOREIGN KEY (FK_CONTACT_ID)
+ REFERENCES public.TBL_CONTACT(ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_ADDRESS__ADDRESS_TYPE_ID_FKEY FOREIGN KEY (FK_ADDRESS_TYPE)
+ REFERENCES public.REF_ADDRESS_TYPE (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+);
+ALTER TABLE public.TBL_ADDRESS
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_ADDRESS TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_tbl_address_uuid ON public.TBL_ADDRESS ( UUID ASC );
+
+INSERT INTO public.TBL_ADDRESS (UUID, FK_CONTACT_ID, FK_ADDRESS_TYPE, IS_MAIN_ADDRESS, POSTCODE, COMMUNITY, COMMUNITY_SUFFIX, STREET, HOUSENUMBER, WGS_84_ZONE, LATITUDE, LONGITUDE, URL_MAP, NOTE) VALUES ( '37e800fe-64f0-4834-8b83-8453cbb936a5', 2, 1, true, '12345', 'Heringsdorf','', 'Flunderweg', '5', '', '53 NL', '3 WB','www.xyz', 'nur über Seeweg erreichbar');
+INSERT INTO public.TBL_ADDRESS (UUID, FK_CONTACT_ID, FK_ADDRESS_TYPE, IS_MAIN_ADDRESS, POSTCODE, COMMUNITY, COMMUNITY_SUFFIX, STREET, HOUSENUMBER, WGS_84_ZONE, LATITUDE, LONGITUDE, URL_MAP, NOTE) VALUES ( '8a1202ae-2532-474e-8367-a1f0e13e9fbd', 1, 2, false, '67890', 'Stralsund','', 'Schollendamm', '18', '', '53 N', '2 WB','www.xyz', 'Hochwassergefahr');
+
+
+-- ---------------------------------------------
+-- TABLE TBL_COMMUNICATION
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_communication_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_communication_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.TBL_COMMUNICATION
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_communication_id_seq'::regclass),
+ UUID uuid NOT NULL,
+ FK_CONTACT_ID bigint NOT NULL,
+ FK_COMMUNICATION_TYPE bigint,
+ COMMUNICATION_DATA character varying(1024),
+ NOTE character varying(255),
+
+ CONSTRAINT TBL_COMMUNICATION_PKEY PRIMARY KEY (ID),
+ CONSTRAINT TBL_COMMUNICATION__CONTACT_ID_FKEY FOREIGN KEY (FK_CONTACT_ID)
+ REFERENCES public.TBL_CONTACT(ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_COMMUNICATION__COMMUNICATION_TYPE_ID_FKEY FOREIGN KEY (FK_COMMUNICATION_TYPE)
+ REFERENCES public.REF_COMMUNICATION_TYPE (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+);
+ALTER TABLE public.TBL_COMMUNICATION
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_COMMUNICATION TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_tbl_communication_uuid ON public.TBL_COMMUNICATION ( UUID ASC );
+
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( '25f6d7cc-b168-4dd5-a36d-6f14b2f956e9', 2, 2, 'bitte melden Sie sich bei uns', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( 'a5fa380e-8f33-4ea7-9416-e03d11b91cae', 1, 3, 'bitte melden zwecks Terminabstimmung', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( 'c0dcef80-ca07-48b7-a3ed-2c99c4388928', 1, 1, 'info@bigbang.com', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( 'd19d9e10-d2dd-4383-84ec-2fe96421c0a3', 2, 1, 'info@pharmapeekltd.com', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( '234b63e4-d8db-48ab-899f-0320903c01af', 3, 1, 'reinbold.tab@pharmapeek.com', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( '11e25c02-de00-430d-b6cd-f02f7c60e026', 5, 1, 'PaulineF@gmx.net', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( '9ca29c3b-e189-4ce9-9401-15001c769627', 6, 1, 'mo@gmail.com', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( '05505b1a-61df-45c0-b006-64165cbadfa2', 7, 1, 'MGruebelSport@fogger.mil', 'Info...');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA, NOTE) VALUES ( 'b52dabaf-d156-4fd0-a07c-510673112a15', 8, 1, 'Mini.osterbrink@yahoo.ie', 'Info...');
+
+-- ---------------------------------------------
+-- TABLE TBL_COMPANY
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_company_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_company_id_seq
+ OWNER TO CBD_SERVICE;
+
+
+CREATE TABLE public.TBL_COMPANY
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_company_id_seq'::regclass),
+ COMPANY_NAME character varying(255),
+ COMPANY_TYPE character varying(30),
+ HR_NUMBER character varying(255),
+ FK_CONTACT_ID bigint NOT NULL,
+ CONSTRAINT TBL_COMPANY_PKEY PRIMARY KEY (id),
+ CONSTRAINT TBL_COMPANY__CONTACT_ID_FKEY FOREIGN KEY (FK_CONTACT_ID)
+ REFERENCES public.TBL_CONTACT(ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+);
+ALTER TABLE public.TBL_COMPANY
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_COMPANY TO CBD_SERVICE;
+
+INSERT INTO public.TBL_COMPANY (COMPANY_NAME, COMPANY_TYPE, HR_NUMBER, FK_CONTACT_ID) VALUES ( 'BigBang Logistic', 'Logistik', '123', 1 );
+INSERT INTO public.TBL_COMPANY (COMPANY_NAME, COMPANY_TYPE, HR_NUMBER, FK_CONTACT_ID) VALUES ( 'Pharma Peek', 'Pharma', '345', 2 );
+INSERT INTO public.TBL_COMPANY (COMPANY_NAME, COMPANY_TYPE, HR_NUMBER, FK_CONTACT_ID) VALUES ( '***', '***', null, 9 );
+INSERT INTO public.TBL_COMPANY (COMPANY_NAME, COMPANY_TYPE, HR_NUMBER, FK_CONTACT_ID) VALUES ( '***', '***', null, 10 );
+
+
+-- ---------------------------------------------
+-- TABLE TBL_CONTACT_PERSON
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_contact_person_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_contact_person_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.TBL_CONTACT_PERSON
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_contact_person_id_seq'::regclass),
+ FIRST_NAME character varying(255),
+ LAST_NAME character varying(255),
+ TITLE character varying(255),
+ FK_SALUTATION_ID bigint,
+ FK_REF_PERSON_TYPE_ID bigint NULL,
+ FK_CONTACT_ID bigint NOT NULL,
+ FK_COMPANY_ID bigint NOT NULL,
+ CONSTRAINT TBL_CONTACT_PERSON_PKEY PRIMARY KEY (ID),
+ CONSTRAINT TBL_CONTACT_PERSON__CONTACT_ID_FKEY FOREIGN KEY (FK_CONTACT_ID)
+ REFERENCES public.TBL_CONTACT (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_CONTACT_PERSON__PERSON_TYPE_ID_FKEY FOREIGN KEY (FK_REF_PERSON_TYPE_ID)
+ REFERENCES public.REF_PERSON_TYPE (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_CONTACT_PERSON__SALUTATION_ID_FKEY FOREIGN KEY (FK_SALUTATION_ID)
+ REFERENCES public.REF_SALUTATION (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_CONTACT_PERSON__COMPANY_ID_FKEY FOREIGN KEY (FK_COMPANY_ID)
+ REFERENCES public.TBL_COMPANY (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+);
+ALTER TABLE public.TBL_CONTACT_PERSON
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_CONTACT_PERSON TO CBD_SERVICE;
+
+INSERT INTO public.TBL_CONTACT_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, FK_CONTACT_ID, FK_COMPANY_ID) VALUES ( 'Tabea', 'Reinebold', 'Dr.', 2, 1, 3, 2);
+INSERT INTO public.TBL_CONTACT_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, FK_CONTACT_ID, FK_COMPANY_ID) VALUES ( 'Jan', 'Wacker', '', 1, 1, 4, 2);
+INSERT INTO public.TBL_CONTACT_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, FK_CONTACT_ID, FK_COMPANY_ID) VALUES ( '***', '***', null, null, null, 11, 3);
+INSERT INTO public.TBL_CONTACT_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, FK_CONTACT_ID, FK_COMPANY_ID) VALUES ( '***', '***', null, null, null, 12, 2);
+
+-- ---------------------------------------------
+-- TABLE TBL_EXTERNAL_PERSON
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_external_person_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_external_person_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.TBL_EXTERNAL_PERSON
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_external_person_id_seq'::regclass),
+ FIRST_NAME character varying(255),
+ LAST_NAME character varying(255),
+ TITLE character varying(255),
+ FK_SALUTATION_ID bigint,
+ FK_REF_PERSON_TYPE_ID bigint,
+ FK_CONTACT_ID bigint NOT NULL,
+ CONSTRAINT TBL_EXTERNAL_PERSON_PKEY PRIMARY KEY (id),
+ CONSTRAINT TBL_EXTERNAL_PERSON__CONTACT_ID_FKEY FOREIGN KEY (FK_CONTACT_ID)
+ REFERENCES public.TBL_CONTACT (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_EXTERNAL_PERSON__SALUTATION_ID_FKEY FOREIGN KEY (FK_SALUTATION_ID)
+ REFERENCES public.REF_SALUTATION (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_EXTERNAL_PERSON__PERSON_TYPE_ID_FKEY FOREIGN KEY (FK_REF_PERSON_TYPE_ID)
+ REFERENCES public.REF_PERSON_TYPE (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+);
+ALTER TABLE public.TBL_EXTERNAL_PERSON
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_EXTERNAL_PERSON TO CBD_SERVICE;
+
+INSERT INTO public.TBL_EXTERNAL_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, FK_CONTACT_ID) VALUES ( 'Monica', 'Grübel', 'Dipl.-Sportlehrerin', 2, 1, 7);
+INSERT INTO public.TBL_EXTERNAL_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, FK_CONTACT_ID) VALUES ( 'Maurice', 'Fürstenberg', 'B.A.', 2, 2, 8);
+
+
+-- ---------------------------------------------
+-- TABLE TBL_INTERNAL_PERSON
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_internal_person_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_internal_person_id_seq
+ OWNER TO CBD_SERVICE;
+CREATE TABLE public.TBL_INTERNAL_PERSON
+(
+ ID bigint NOT NULL DEFAULT nextval('tbl_internal_person_id_seq'::regclass),
+ FIRST_NAME character varying(255),
+ LAST_NAME character varying(255),
+ TITLE character varying(255),
+ FK_SALUTATION_ID bigint,
+ FK_REF_PERSON_TYPE_ID bigint,
+ DEPARTMENT character varying(255),
+ UID character varying(255),
+ USER_REF character varying(255),
+ FK_CONTACT_ID bigint NOT NULL,
+ CONSTRAINT TBL_INTERNAL_PERSON_PKEY PRIMARY KEY (ID),
+ CONSTRAINT TBL_INTERNAL_PERSON__CONTACT_ID_FKEY FOREIGN KEY (FK_CONTACT_ID)
+ REFERENCES public.TBL_CONTACT (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_INTERNAL_PERSON__SALUTATION_ID_FKEY FOREIGN KEY (FK_SALUTATION_ID)
+ REFERENCES public.REF_SALUTATION (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION,
+ CONSTRAINT TBL_INTERNAL_PERSON__PERSON_TYPE_ID_FKEY FOREIGN KEY (FK_REF_PERSON_TYPE_ID)
+ REFERENCES public.REF_PERSON_TYPE (ID) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+);
+ALTER TABLE public.TBL_INTERNAL_PERSON
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.TBL_INTERNAL_PERSON TO CBD_SERVICE;
+
+CREATE UNIQUE INDEX idx_tbl_internal_person_uid ON public.TBL_INTERNAL_PERSON ( UID ASC );
+CREATE UNIQUE INDEX idx_tbl_internal_person_user_ref ON public.TBL_INTERNAL_PERSON ( USER_REF ASC );
+
+INSERT INTO public.TBL_INTERNAL_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, DEPARTMENT, UID, USER_REF, FK_CONTACT_ID) VALUES ( 'Pauline', 'Freudenberg', 'B.Sc.', 1, 1,'Abteilung Rechnungsstellung', '66cd78c3-6716-4ab3-b834-a199fc796b88', 'PFREUD', 5);
+INSERT INTO public.TBL_INTERNAL_PERSON (FIRST_NAME, LAST_NAME, TITLE, FK_SALUTATION_ID, FK_REF_PERSON_TYPE_ID, DEPARTMENT, UID, USER_REF, FK_CONTACT_ID) VALUES ( 'Bernhardt', 'Iffland', '', 2, 2,'Kreativ', '4124e4e7-3488-4492-bf39-75e6a23a1c1a', 'BIFFL', 6);
+
+-- ---------------------------------------------
+-- TABLE TBL_ASSIGNMENT_MODUL_CONTACT
+-- ---------------------------------------------
+CREATE SEQUENCE public.tbl_assignment_modul_contact_id_seq
+ INCREMENT 1
+ MINVALUE 1
+ MAXVALUE 9223372036854775807
+ START 1
+ CACHE 1;
+ALTER TABLE public.tbl_assignment_modul_contact_id_seq
+ OWNER TO CBD_SERVICE;
+
+CREATE TABLE public.TBL_ASSIGNMENT_MODUL_CONTACT
+(
+ id bigint NOT NULL DEFAULT nextval('tbl_assignment_modul_contact_id_seq'::regclass),
+ uuid uuid NOT NULL,
+ fk_contact_id bigint NOT NULL,
+ modul_name character varying(255),
+ assignment_date timestamp,
+ expiring_date timestamp,
+ deletion_lock_until timestamp,
+ assignment_note character varying(2048),
+ CONSTRAINT tbl_assignment_modul_contact_pkey PRIMARY KEY (id),
+ CONSTRAINT tbl_assignment_modul_contact_id_fkey FOREIGN KEY (fk_contact_id)
+ REFERENCES public.tbl_contact (id) MATCH SIMPLE
+ ON UPDATE NO ACTION ON DELETE NO ACTION
+)
+WITH (
+ OIDS=FALSE
+);
+ALTER TABLE public.tbl_assignment_modul_contact
+ OWNER TO cbd_service;
+GRANT ALL ON TABLE public.tbl_assignment_modul_contact TO cbd_service;
+
+INSERT INTO public.tbl_assignment_modul_contact(uuid, fk_contact_id, modul_name, assignment_date, expiring_date, deletion_lock_until, assignment_note) VALUES ( 'dfc2979c-40e3-11ea-b77f-2e728ce88125', 1, 'Betriebstagebuch', '2020-01-19 10:23:54', '2021-01-19 00:00:00', '2021-01-19 00:00:00', 'seit Januar zugeordnet');
+INSERT INTO public.tbl_assignment_modul_contact(uuid, fk_contact_id, modul_name, assignment_date, expiring_date, deletion_lock_until, assignment_note) VALUES ( '4009bce2-40e5-11ea-b77f-2e728ce88125', 1, 'Störinfos', '2020-02-27 10:23:54', '2019-02-27 00:00:00', '2019-02-27 00:00:00', 'seit Februar zugeordnet');
+
+-- -------------------------------------
+-- VIEWS -------------------------------
+-- -------------------------------------
+DROP VIEW IF EXISTS VW_GENERAL_CONTACT CASCADE;
+
+CREATE VIEW VW_GENERAL_CONTACT
+AS
+SELECT g.id,
+ c.uuid,
+ g.name,
+ c.contact_type,
+ g.fk_contact_id,
+ g.company_name,
+ g.company_type,
+ g.fk_salutation_id,
+ g.fk_ref_person_type_id,
+ g.title,
+ g.first_name,
+ g.last_name,
+ g.department,
+ c.note,
+ c.anonymized
+FROM tbl_contact c
+INNER JOIN (
+
+SELECT id,
+ company_name as name,
+ fk_contact_id,
+ company_name,
+ company_type,
+ null as fk_salutation_id,
+ null as fk_ref_person_type_id,
+ null as title,
+ null as first_name,
+ null as last_name,
+ null as department
+FROM tbl_company company
+
+UNION
+
+SELECT p.id,
+ COALESCE(p.last_name, '') || ' ' || COALESCE(p.first_name,'') || ' [' || COALESCE(c.company_name, '') || ']' as name,
+ p.fk_contact_id,
+ c.company_name,
+ c.company_type,
+ p.fk_salutation_id,
+ p.fk_ref_person_type_id,
+ p.title,
+ p.first_name,
+ p.last_name,
+ null as department
+FROM tbl_contact_person p
+INNER JOIN tbl_company c ON c.id = p.fk_company_id
+
+UNION
+
+SELECT id,
+ COALESCE(last_name, '') || ' ' || COALESCE(first_name, '') as name,
+ fk_contact_id,
+ null as company_name,
+ null as company_type,
+ fk_salutation_id,
+ fk_ref_person_type_id,
+ title,
+ first_name,
+ last_name,
+ department
+FROM tbl_internal_person
+
+UNION
+
+SELECT id,
+ COALESCE(last_name, '') || ' ' || COALESCE(first_name, '') as name,
+ fk_contact_id,
+ null as company_name,
+ null as company_type,
+ fk_salutation_id,
+ fk_ref_person_type_id,
+ title,
+ first_name,
+ last_name,
+ null as department
+FROM tbl_external_person
+ ) g
+ON g.fk_contact_id = c.ID;
+
+ALTER VIEW public.VW_GENERAL_CONTACT
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.VW_GENERAL_CONTACT TO CBD_SERVICE;
+
+
+DROP VIEW IF EXISTS VW_DETAILED_CONTACT;
+
+CREATE VIEW VW_DETAILED_CONTACT
+AS
+SELECT c.id,
+ c.uuid,
+ c.name,
+ c.contact_type,
+ c.fk_contact_id,
+ c.company_name,
+ c.company_type,
+ c.anonymized,
+ s.uuid as salutation_uuid,
+ t.uuid as person_type_uuid,
+ c.title,
+ c.first_name,
+ c.last_name,
+ c.department,
+ c.note,
+ s.type as salutation_type,
+ t.type as person_type,
+ a.street,
+ a.housenumber,
+ a.community,
+ com.communication_data as email,
+
+ UPPER(
+ COALESCE(c.name, '') || '|@|'
+ || COALESCE(company_name, '') || '|@|'
+ || COALESCE(c.company_type, '') || '|@|'
+ || COALESCE(c.title, '') || '|@|'
+ || COALESCE(c.first_name, '') || '|@|'
+ || COALESCE(c.last_name, '') || '|@|'
+ || COALESCE(c.department, '') || '|@|'
+ || COALESCE(c.note, '') || '|@|'
+ || COALESCE(s.type, '') || '|@|'
+ || COALESCE(t.type, '') || '|@|'
+ || COALESCE(a.street, '') || '|@|'
+ || COALESCE(a.housenumber, '') || '|@|'
+ || COALESCE(a.community, '') || '|@|'
+ || COALESCE(com.communication_data, '')
+ )as searchfield
+FROM VW_GENERAL_CONTACT c
+LEFT OUTER JOIN ref_salutation s ON c.fk_salutation_id = s.id
+LEFT OUTER JOIN tbl_address a ON a.fk_contact_id = c.fk_contact_id and is_main_address = true
+LEFT OUTER JOIN ref_person_type t ON c.fk_ref_person_type_id = t.id
+LEFT OUTER JOIN tbl_communication com ON (com.fk_contact_id = c.fk_contact_id AND com.fk_communication_type =
+ (SELECT ct.id FROM ref_communication_type ct WHERE ct.type_email = true)) ;
+
+ALTER VIEW public.VW_DETAILED_CONTACT
+ OWNER TO CBD_SERVICE;
+GRANT ALL ON TABLE public.VW_DETAILED_CONTACT TO CBD_SERVICE;
+
+
+
+
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java b/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
index ed0fcf1..8d0468d 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
@@ -114,4 +114,7 @@
@Bean
public AssignmentModulContactService myAssignmentModulContactService() { return new AssignmentModulContactService(); }
+
+ @Bean
+ public ContactAnonymizerService myContactAnonymizerService() { return new ContactAnonymizerService(); }
}
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java
index ebe1c07..ae2e2c5 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java
@@ -15,6 +15,7 @@
package org.eclipse.openk.contactbasedata.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.http.HttpStatus;
import org.eclipse.openk.contactbasedata.ContactBaseDataApplication;
import org.eclipse.openk.contactbasedata.service.CommunicationTypeService;
import org.eclipse.openk.contactbasedata.support.MockDataHelper;
@@ -28,10 +29,12 @@
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
+
import java.util.List;
import java.util.UUID;
+
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -115,9 +118,21 @@
@Test
public void shouldDeleteCommunicationType() throws Exception {
- mockMvc.perform(delete("/communication-types/05ff2344-20a5-11ea-978f-2e728ce88125")
+ UUID uuid = UUID.fromString("05ff2344-20a5-11ea-978f-2e728ce88125");
+ doNothing().when(communicationTypeService).removeCommunicationType(isA(UUID.class));
+ mockMvc.perform(delete("/communication-types/"+uuid.toString())
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful());
+ verify(communicationTypeService, times( 1 )).removeCommunicationType(uuid);
+ }
+
+ @Test
+ public void shouldFailWithDeleteCommunicationType() throws Exception {
+ UUID uuid = UUID.fromString("05ff2344-20a5-11ea-978f-2e728ce88125");
+ doThrow(new RuntimeException("Base Exception")).when(communicationTypeService).removeCommunicationType(isA(UUID.class));
+ mockMvc.perform(delete("/communication-types/"+uuid.toString())
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().is(HttpStatus.SC_CONFLICT));
}
}
\ No newline at end of file
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/CompanyControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/CompanyControllerTest.java
index 1448b60..1d47783 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/CompanyControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/CompanyControllerTest.java
@@ -37,6 +37,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -71,7 +72,7 @@
public void shouldReturnAllCompany() throws Exception {
Page<CompanyDto> epPage = MockDataHelper.mockCompanyDtoPage();
- when(companyService.findCompanies(any(Pageable.class))).thenReturn(epPage);
+ when(companyService.findCompanies(anyBoolean(), any(Pageable.class))).thenReturn(epPage);
mockMvc.perform(get("/companies"))
.andExpect(status().is2xxSuccessful())
@@ -123,7 +124,7 @@
public void shouldReturnContactPerson() throws Exception {
List<ContactPersonDto> contactPersonDtos = MockDataHelper.mockContactPersonDtos();
- when( companyService.findContactPersonsToCompany(any(UUID.class))).thenReturn(contactPersonDtos);
+ when( companyService.findContactPersonsToCompany(any(UUID.class), anyBoolean())).thenReturn(contactPersonDtos);
mockMvc.perform(get("/companies/"+UUID.randomUUID().toString()+"/contact-persons" ))
.andExpect(status().is2xxSuccessful())
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java
index 841fe76..86db98c 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java
@@ -17,6 +17,7 @@
import org.eclipse.openk.contactbasedata.ContactBaseDataApplication;
import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
import org.eclipse.openk.contactbasedata.service.ContactService;
+import org.eclipse.openk.contactbasedata.service.util.SearchContactsFilterParams;
import org.eclipse.openk.contactbasedata.support.MockDataHelper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,7 +31,7 @@
import org.springframework.test.web.servlet.MockMvc;
import static org.hamcrest.Matchers.is;
-import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -53,8 +54,7 @@
public void shouldReturnAllContacts() throws Exception {
Page<VwDetailedContact> retPage = MockDataHelper.mockVDetailedContactPage();
- when(contactService.findDetailedContacts(
- isNull(), isNull(), isNull(), isNull(), anyBoolean(), anyBoolean(), any(Pageable.class))).thenReturn(retPage);
+ when(contactService.findDetailedContacts(any(SearchContactsFilterParams.class), any(Pageable.class))).thenReturn(retPage);
mockMvc.perform(get("/contacts"))
.andExpect(status().is2xxSuccessful())
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonControllerTest.java
index 9ceef5d..e844db2 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/ExternalPersonControllerTest.java
@@ -35,6 +35,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -69,7 +70,7 @@
public void shouldReturnAllExtPerson() throws Exception {
Page<ExternalPersonDto> epPage = MockDataHelper.mockExternalPersonDtoPage();
- when(externalPersonService.findExternalPersons(any(Pageable.class))).thenReturn(epPage);
+ when(externalPersonService.findExternalPersons(anyBoolean(), any(Pageable.class))).thenReturn(epPage);
mockMvc.perform(get("/external-persons"))
.andExpect(status().is2xxSuccessful())
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/InternalPersonControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/InternalPersonControllerTest.java
index f899812..38e135b 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/InternalPersonControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/InternalPersonControllerTest.java
@@ -34,8 +34,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -70,7 +69,7 @@
public void shouldReturnAllIntPersons() throws Exception {
Page<InternalPersonDto> ipPage = MockDataHelper.mockInternalPersonDtoPage();
- when(internalPersonService.findInternalPersons(anyString(), anyString(), any(Pageable.class))).thenReturn(ipPage);
+ when(internalPersonService.findInternalPersons(anyBoolean(), anyString(), anyString(), any(Pageable.class))).thenReturn(ipPage);
mockMvc.perform(get("/internal-persons?uid=ABC&userRef=123"))
.andExpect(status().is2xxSuccessful())
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java
index 9a89a99..fb6d18e 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java
@@ -31,6 +31,8 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ContextConfiguration;
import java.util.List;
@@ -39,7 +41,7 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
@@ -70,6 +72,24 @@
assertEquals(ep.getContact().getUuid(), dto.getContactUuid());
}
+
+ @Test
+ public void shouldFindSeveralCompaniesProperly() {
+ Page<TblCompany> page1 = MockDataHelper.mockCompanyPage();
+ Page<TblCompany> page2 = MockDataHelper.mockCompanyPage();
+ when(companyRepository.findAll(any(Pageable.class))).thenReturn(page1);
+ when(companyRepository.findByContact_anonymizedFalseOrContact_anonymizedIsNull(any(Pageable.class))).thenReturn(page2);
+ Page<CompanyDto> dtos1 = companyService.findCompanies(true, Pageable.unpaged());
+ Page<CompanyDto> dtos2 = companyService.findCompanies(false, Pageable.unpaged());
+
+ assertEquals(page1.getContent().get(0).getContact().getUuid(), dtos1.get().findFirst().get().getContactUuid());
+ assertEquals(page2.getContent().get(1).getContact().getUuid(), dtos2.getContent().get(1).getContactUuid());
+ assertNotEquals(dtos1.getContent().get(0).getContactUuid(), dtos2.getContent().get(0).getContactUuid());
+
+ verify(companyRepository, times(1)).findAll(any(Pageable.class));
+ verify(companyRepository, times(1))
+ .findByContact_anonymizedFalseOrContact_anonymizedIsNull(any(Pageable.class));
+ }
@Test
public void shouldThrowInErrorCaseWithCompany() {
TblCompany ep = MockDataHelper.mockCompany();
@@ -148,16 +168,20 @@
public void findContactPersonsToCompanyWithSuccess() {
TblCompany company = MockDataHelper.mockCompany();
company.setContactPersons( MockDataHelper.mockTblContactPersons());
+ company.getContactPersons().get(1).getContact().setAnonymized(true);
when(companyRepository.findByTblContactUuid(any(UUID.class))).thenReturn(Optional.of(company));
- List<ContactPersonDto> cpDtos = companyService.findContactPersonsToCompany(UUID.randomUUID());
+ List<ContactPersonDto> cpDtos = companyService.findContactPersonsToCompany(UUID.randomUUID(), true);
assertEquals(company.getContactPersons().size(), cpDtos.size());
assertEquals(company.getContactPersons().get(1).getContact().getUuid(), cpDtos.get(1).getContactUuid());
+
+ List<ContactPersonDto> cpDtos2 = companyService.findContactPersonsToCompany(UUID.randomUUID(), false);
+ assertNotEquals(cpDtos.size(), cpDtos2.size());
}
@Test
public void findContactPersonsToCompanyWithException() {
when(companyRepository.findByTblContactUuid(any(UUID.class))).thenReturn(Optional.empty());
- assertThrows( NotFoundException.class, ()-> companyService.findContactPersonsToCompany(UUID.randomUUID()));
+ assertThrows( NotFoundException.class, ()-> companyService.findContactPersonsToCompany(UUID.randomUUID(), false));
}
}
\ No newline at end of file
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/ContactAnonymizerServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/ContactAnonymizerServiceTest.java
new file mode 100644
index 0000000..60906b5
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/ContactAnonymizerServiceTest.java
@@ -0,0 +1,182 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.contactbasedata.service;
+
+import org.eclipse.openk.contactbasedata.config.TestConfiguration;
+import org.eclipse.openk.contactbasedata.constants.Constants;
+import org.eclipse.openk.contactbasedata.model.TblContact;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.*;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.ContextConfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.when;
+
+@DataJpaTest
+@ContextConfiguration(classes = {TestConfiguration.class})
+public class ContactAnonymizerServiceTest {
+ @Qualifier("myContactAnonymizerService")
+ @Autowired
+ private ContactAnonymizerService contactAnonymizerService;
+
+ @MockBean
+ private ContactService contactService;
+
+ @MockBean
+ private InternalPersonService internalPersonService;
+
+ @MockBean
+ private ExternalPersonService externalPersonService;
+
+ @MockBean
+ private CompanyService companyService;
+
+ @MockBean
+ private ContactPersonService contactPersonService;
+
+ @MockBean
+ private AddressService addressService;
+
+ @MockBean
+ private CommunicationService communicationService;
+
+ @Test
+ public void shouldAnonymizeInternalPerson() {
+ UUID theContactUuid = UUID.randomUUID();
+ TblContact tblIntPers = MockDataHelper.mockTblContact();
+ tblIntPers.setUuid(theContactUuid);
+ tblIntPers.setContactType(Constants.CONTACT_TYPE_INTERNAL_PERSON);
+ when( contactService.findTblContact(theContactUuid)).thenReturn(tblIntPers);
+
+ InternalPersonDto ipDto = MockDataHelper.mockInternalPersonDto();
+ ipDto.setContactUuid(theContactUuid);
+ when( internalPersonService.findInternalPerson(theContactUuid))
+ .thenReturn(ipDto);
+
+ List<AddressDto> addressDtos = MockDataHelper.mockAddressDtoList();
+ when( addressService.getAddressesByContactUuid(theContactUuid)).thenReturn(addressDtos);
+
+ List<CommunicationDto> communicationDtos = MockDataHelper.mockCommunicationDtoList();
+ when( communicationService.getCommunicationsByContactUuid(theContactUuid)).thenReturn(communicationDtos);
+
+ assertNull( ipDto.getContactAnonymized());
+ assertNotEquals( Constants.ANONYMOUS_TAG, addressDtos.get(0).getCommunity());
+ assertNotEquals( Constants.ANONYMOUS_TAG, communicationDtos.get(0).getCommunicationData());
+
+ contactAnonymizerService.anonymize(theContactUuid);
+
+ assertTrue( ipDto.getContactAnonymized());
+ assertEquals( Constants.ANONYMOUS_TAG , ipDto.getLastName());
+ assertNull( ipDto.getFirstName());
+ assertNull( ipDto.getSalutationUuid());
+ assertEquals( Constants.ANONYMOUS_TAG, addressDtos.get(0).getCommunity());
+ assertEquals( Constants.ANONYMOUS_TAG, communicationDtos.get(0).getCommunicationData());
+ }
+
+ @Test
+ public void shouldAnonymizeExternalPerson() {
+ UUID theContactUuid = UUID.randomUUID();
+ TblContact tblExtPers = MockDataHelper.mockTblContact();
+ tblExtPers.setUuid(theContactUuid);
+ tblExtPers.setContactType(Constants.CONTACT_TYPE_EXTERNAL_PERSON);
+ when( contactService.findTblContact(theContactUuid)).thenReturn(tblExtPers);
+
+ ExternalPersonDto epDto = MockDataHelper.mockExternalPersonDto();
+ epDto.setContactUuid(theContactUuid);
+ when( externalPersonService.findExternalPerson(theContactUuid))
+ .thenReturn(epDto);
+
+ List<AddressDto> addressDtos = MockDataHelper.mockAddressDtoList();
+ when( addressService.getAddressesByContactUuid(theContactUuid)).thenReturn(addressDtos);
+
+ List<CommunicationDto> communicationDtos = MockDataHelper.mockCommunicationDtoList();
+ when( communicationService.getCommunicationsByContactUuid(theContactUuid)).thenReturn(communicationDtos);
+
+ contactAnonymizerService.anonymize(theContactUuid);
+
+ assertTrue( epDto.getContactAnonymized());
+ assertEquals( Constants.ANONYMOUS_TAG, epDto.getLastName() );
+ assertNull( epDto.getFirstName());
+ assertNull( epDto.getSalutationUuid());
+ assertEquals( Constants.ANONYMOUS_TAG, addressDtos.get(0).getCommunity());
+ assertEquals( Constants.ANONYMOUS_TAG, communicationDtos.get(0).getCommunicationData());
+
+ }
+
+
+ @Test
+ public void shouldAnonymizeCompany() {
+ UUID theContactUuid = UUID.randomUUID();
+ TblContact tblCompany = MockDataHelper.mockTblContact();
+ tblCompany.setUuid(theContactUuid);
+ tblCompany.setContactType(Constants.CONTACT_TYPE_COMPANY);
+ when( contactService.findTblContact(theContactUuid)).thenReturn(tblCompany);
+
+ CompanyDto companyDto = MockDataHelper.mockCompanyDto();
+ companyDto.setContactUuid(theContactUuid);
+ when( companyService.findCompany(theContactUuid))
+ .thenReturn(companyDto);
+
+ List<ContactPersonDto> contactPersonDtos = MockDataHelper.mockContactPersonDtos();
+ when( companyService.findContactPersonsToCompany(theContactUuid, false))
+ .thenReturn(contactPersonDtos);
+
+ UUID cp0UUID = contactPersonDtos.get(0).getContactUuid();
+ UUID cp1UUID = contactPersonDtos.get(1).getContactUuid();
+ when(contactPersonService.findContactPerson(cp0UUID)).thenReturn(contactPersonDtos.get(0));
+ when(contactPersonService.findContactPerson(cp1UUID)).thenReturn(contactPersonDtos.get(1));
+
+ // Addresses and communications for the company
+ List<AddressDto> addressDtos = MockDataHelper.mockAddressDtoList();
+ when( addressService.getAddressesByContactUuid(theContactUuid)).thenReturn(addressDtos);
+ List<CommunicationDto> communicationDtos = MockDataHelper.mockCommunicationDtoList();
+ when( communicationService.getCommunicationsByContactUuid(theContactUuid)).thenReturn(communicationDtos);
+
+ // Addresses and communications for the first contact person
+ List<AddressDto> addressDtosForCp = MockDataHelper.mockAddressDtoList();
+ when( addressService.getAddressesByContactUuid(cp0UUID)).thenReturn(addressDtosForCp);
+ when( addressService.getAddressesByContactUuid(cp1UUID)).thenReturn(new ArrayList<>());
+ List<CommunicationDto> communicationDtosForCp = MockDataHelper.mockCommunicationDtoList();
+ when( communicationService.getCommunicationsByContactUuid(cp0UUID)).thenReturn(new ArrayList<>());
+ when( communicationService.getCommunicationsByContactUuid(cp1UUID)).thenReturn(communicationDtosForCp);
+
+ contactAnonymizerService.anonymize(theContactUuid);
+
+ assertTrue( companyDto.getContactAnonymized());
+ assertEquals( Constants.ANONYMOUS_TAG, companyDto.getCompanyName() );
+ assertNull( companyDto.getCompanyType());
+ assertEquals( Constants.ANONYMOUS_TAG, addressDtos.get(0).getCommunity() );
+ assertEquals( Constants.ANONYMOUS_TAG, communicationDtos.get(0).getCommunicationData() );
+
+ assertTrue( contactPersonDtos.get(0).getContactAnonymized());
+ assertTrue( contactPersonDtos.get(1).getContactAnonymized());
+ assertEquals( Constants.ANONYMOUS_TAG, contactPersonDtos.get(0).getLastName() );
+ assertEquals( Constants.ANONYMOUS_TAG, contactPersonDtos.get(1).getLastName() );
+ assertNull( contactPersonDtos.get(0).getFirstName());
+ assertNull( contactPersonDtos.get(1).getFirstName());
+ assertEquals( Constants.ANONYMOUS_TAG, addressDtosForCp.get(0).getCommunity() );
+ assertEquals( Constants.ANONYMOUS_TAG, communicationDtosForCp.get(0).getCommunicationData() );
+
+ }
+}
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java
index f3ed1c4..b26b72b 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java
@@ -17,6 +17,7 @@
import org.eclipse.openk.contactbasedata.config.TestConfiguration;
import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
import org.eclipse.openk.contactbasedata.repository.DetailedContactRepository;
+import org.eclipse.openk.contactbasedata.service.util.SearchContactsFilterParams;
import org.eclipse.openk.contactbasedata.support.MockDataHelper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,8 +29,10 @@
import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ContextConfiguration;
+import java.util.Date;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
//@RunWith(SpringRunner.class)
@@ -47,9 +50,11 @@
@Test
public void shouldFindDetailedContactsProperly() {
Page<VwDetailedContact> mockPaged = MockDataHelper.mockVDetailedContactPage();
- when(detailedContactRepository.findAll(any(Pageable.class))).thenReturn(mockPaged);
+ when(detailedContactRepository.findByFilter(isNull(), isNull(), isNull(), isNull(),
+ anyBoolean(), any( Date.class), anyBoolean(), anyBoolean(), anyBoolean(), any(Pageable.class))).thenReturn(mockPaged);
+ SearchContactsFilterParams filter = new SearchContactsFilterParams();
Page<VwDetailedContact> retPage = contactService.findDetailedContacts(
- null, null, null, null, false, false, PageRequest.of(0, 20));
+ filter, PageRequest.of(0, 20));
assertEquals(mockPaged.getTotalElements(), retPage.getTotalElements());
}
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/ExternalPersonServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/ExternalPersonServiceTest.java
index 3dd2d0e..0bfe889 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/service/ExternalPersonServiceTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/ExternalPersonServiceTest.java
@@ -32,6 +32,8 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ContextConfiguration;
import java.util.Optional;
@@ -39,7 +41,7 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
@@ -71,6 +73,24 @@
}
@Test
+ public void shouldFindSeveralExternalPersonsProperly() {
+ Page<TblExternalPerson> page1 = MockDataHelper.mockExternalPersonPage();
+ Page<TblExternalPerson> page2 = MockDataHelper.mockExternalPersonPage();
+ when(externalPersonRepository.findAll(any(Pageable.class))).thenReturn(page1);
+ when(externalPersonRepository.findByContact_anonymizedFalseOrContact_anonymizedIsNull(any(Pageable.class))).thenReturn(page2);
+ Page<ExternalPersonDto> dtos1 = externalPersonService.findExternalPersons(true, Pageable.unpaged());
+ Page<ExternalPersonDto> dtos2 = externalPersonService.findExternalPersons(false, Pageable.unpaged());
+
+ assertEquals(page1.getContent().get(0).getContact().getUuid(), dtos1.get().findFirst().get().getContactUuid());
+ assertEquals(page2.getContent().get(1).getContact().getUuid(), dtos2.getContent().get(1).getContactUuid());
+ assertNotEquals(dtos1.getContent().get(0).getContactUuid(), dtos2.getContent().get(0).getContactUuid());
+
+ verify(externalPersonRepository, times(1)).findAll(any(Pageable.class));
+ verify(externalPersonRepository, times(1))
+ .findByContact_anonymizedFalseOrContact_anonymizedIsNull(any(Pageable.class));
+ }
+
+ @Test
public void shouldThrowInErrorCaseWithExternalPerson() {
TblExternalPerson ep = MockDataHelper.mockExternalPerson();
when(externalPersonRepository.findByTblContactUuid(any(UUID.class))).thenReturn(Optional.empty());
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/InternalPersonServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/InternalPersonServiceTest.java
index 0c94c90..b40b879 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/service/InternalPersonServiceTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/InternalPersonServiceTest.java
@@ -79,8 +79,8 @@
when(internalPersonRepository.findAll(any(Pageable.class))).thenReturn(ipPage);
when(internalPersonRepository.findByFilter(anyString(), anyString(), any(Pageable.class))).thenReturn(ipPage);
- Page<InternalPersonDto> dtoPage = internalPersonService.findInternalPersons(null, null, Pageable.unpaged());
- Page<InternalPersonDto> dtoPage2= internalPersonService.findInternalPersons("abc", "123", Pageable.unpaged());
+ Page<InternalPersonDto> dtoPage = internalPersonService.findInternalPersons( true, null, null, Pageable.unpaged());
+ Page<InternalPersonDto> dtoPage2= internalPersonService.findInternalPersons( false, "abc", "123", Pageable.unpaged());
verify( internalPersonRepository, times(1)).findAll(any(Pageable.class));
verify( internalPersonRepository, times( 1 )).findByFilter(anyString(), anyString(), any(Pageable.class));
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java b/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
index e451828..54e216e 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
@@ -87,6 +87,15 @@
return epd;
}
+ public static Page<TblExternalPerson> mockExternalPersonPage() {
+ TblExternalPerson ep1 = mockExternalPerson();
+ TblExternalPerson ep2 = mockExternalPerson();
+ ep2.setFirstName("Strofanov");
+ ep2.getContact().setUuid(UUID.randomUUID());
+ List<TblExternalPerson> list = Arrays.asList(ep1, ep2);
+ return new PageImpl<>(list, Pageable.unpaged(), list.size());
+ }
+
public static Page<ExternalPersonDto> mockExternalPersonDtoPage() {
ExternalPersonDto ep1 = mockExternalPersonDto();
ExternalPersonDto ep2 = mockExternalPersonDto();
@@ -467,6 +476,18 @@
return tblCompany;
}
+ public static Page<TblCompany> mockCompanyPage(){
+
+ TblCompany com1 = mockCompany();
+
+ TblCompany com2 = mockCompany();
+ com2.setCompanyName("Sputnik 2000");
+ com2.setCompanyType("AG");
+
+ List<TblCompany> list = Arrays.asList(com1, com2);
+ return new PageImpl<>(list, Pageable.unpaged(), list.size());
+ }
+
public static Page<CompanyDto> mockCompanyDtoPage(){
CompanyDto com1 = mockCompanyDto();