Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.contactBaseData.backend into KON_39-Maske-Interne-Person-hinzufuegen
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/AddressController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/AddressController.java
new file mode 100644
index 0000000..e5ef1be
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/AddressController.java
@@ -0,0 +1,104 @@
+/*
+ *******************************************************************************
+ * 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.controller;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.service.AddressService;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.*;
+import java.util.List;
+import java.util.UUID;
+
+@Log4j2
+@RestController
+@RequestMapping("contacts/")
+public class AddressController {
+ @Autowired
+ private AddressService addressService;
+
+ @GetMapping("/{contactUuid}/addresses")
+ @ApiOperation(value = "Anzeigen aller Adressen zu einem Kontakt")
+ @ApiResponses(value = {
+ @ApiResponse(code = 400, message = "Ungültige Anfrage."),
+ @ApiResponse(code = 200, message = "Suche durchgeführt")})
+ @ResponseStatus(HttpStatus.OK)
+ public List<AddressDto> getContactAddresses(@PathVariable UUID contactUuid) {
+ return addressService.getAddressesByContactUuid(contactUuid);
+ }
+
+
+// @GetMapping("/{salutationUuid}")
+// @ApiOperation(value = "Suchen einer Anrede per UUID")
+// @ResponseStatus(HttpStatus.OK)
+// @ApiResponses(value = {
+// @ApiResponse(code = 400, message = "Ungültige Anfrage."),
+// @ApiResponse(code = 200, message = "Anrede gefunden")})
+// public SalutationDto getSalutation(@PathVariable UUID salutationUuid) {
+//
+// return salutationService.getSalutationByUuid(salutationUuid);
+// }
+//
+//
+// @PostMapping
+// @ApiOperation(value = "Anlegen einer neuen Anrede")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "Anrede erfolgreich angelegt"),
+// @ApiResponse(code = 500, message = "Konnte nicht durchgeführt werden")
+// })
+// public ResponseEntity<SalutationDto> insertSalutation(@Validated @RequestBody SalutationDto salutationDto) {
+// SalutationDto savedSalutationDto = salutationService.insertSalutation(salutationDto);
+// URI location = ServletUriComponentsBuilder
+// .fromCurrentRequestUri()
+// .path("/{uuid}")
+// .buildAndExpand(savedSalutationDto.getUuid())
+// .toUri();
+// return ResponseEntity.created(location).body(savedSalutationDto);
+// }
+//
+//
+// @PutMapping("/{salutationUuid}")
+// @ApiOperation(value = "Ändern einer Anrede")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "Anrede wurde erfolgreich aktualisiert"),
+// @ApiResponse(code = 400, message = "Ungültige Eingabe"),
+// @ApiResponse(code = 404, message = "Nicht gefunden")})
+// public ResponseEntity updateSupplier(@PathVariable UUID salutationUuid, @Validated @RequestBody SalutationDto salutationDto) {
+//
+// if (!salutationDto.getUuid().equals(salutationUuid)) {
+// throw new BadRequestException("invalid.uuid.path.object");
+// }
+//
+// salutationService.updateSalutation(salutationDto);
+// return ResponseEntity.ok().build();
+// }
+//
+//
+// @DeleteMapping("/{uuid}")
+// @ResponseStatus(HttpStatus.OK)
+// @ApiOperation(value = "Anrede löschen")
+// @ApiResponses(value = {
+// @ApiResponse(code = 204, message = "Erfolgreich durchgeführt"),
+// @ApiResponse(code = 400, message = "Ungültige Anfrage"),
+// @ApiResponse(code = 404, message = "Nicht gefunden")})
+// public void removeSalutation(@PathVariable UUID uuid) {
+// salutationService.removeSalutation(uuid);
+// }
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeController.java
new file mode 100644
index 0000000..fe6b031
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeController.java
@@ -0,0 +1,98 @@
+package org.eclipse.openk.contactbasedata.controller;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
+import org.eclipse.openk.contactbasedata.service.CommunicationTypeService;
+import org.eclipse.openk.contactbasedata.service.ExternalPersonService;
+import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
+import org.eclipse.openk.contactbasedata.viewmodel.ExternalPersonDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+
+import java.net.URI;
+import java.util.List;
+import java.util.UUID;
+
+@Log4j2
+@RestController
+@RequestMapping("/communication-types")
+public class CommunicationTypeController {
+ @Autowired
+ private CommunicationTypeService communicationTypeService;
+
+
+ @GetMapping("/{communicationTypeUuid}")
+ @ApiOperation(value = "Anzeigen eines Kommunikationstyps")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
+ @ApiResponse(code = 404, message = "Person wurde nicht gefunden")})
+ @ResponseStatus(HttpStatus.OK)
+ public CommunicationTypeDto getCommunicationType(@PathVariable UUID communicationTypeUuid) {
+ return communicationTypeService.findCommunicationType(communicationTypeUuid);
+ }
+
+ @GetMapping
+ @ApiOperation(value = "Anzeigen aller Kommunikationstypen")
+ @ResponseStatus(HttpStatus.OK)
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
+ public List<CommunicationTypeDto> getCommunicationTypes(){
+ return communicationTypeService.findCommunicationTypes();
+ }
+
+ @PostMapping
+ @ApiOperation(value = "Anlegen eines Kommunikationstyps")
+ @ApiResponses(value = {
+ @ApiResponse(code = 201, message = "Kommunikationstyp erfolgreich angelegt"),
+ @ApiResponse(code = 500, message = "Konnte nicht durchgeführt werden")
+ })
+ public ResponseEntity<CommunicationTypeDto> insertCommunicationType(
+ @Validated @RequestBody CommunicationTypeDto communicationTypeDto) {
+ CommunicationTypeDto savedCommunicationTypeDto = communicationTypeService.insertCommunicationType(communicationTypeDto);
+ URI location = ServletUriComponentsBuilder
+ .fromCurrentRequestUri()
+ .path("/{uuid}")
+ .buildAndExpand(savedCommunicationTypeDto.getUuid())
+ .toUri();
+ return ResponseEntity.created(location).body(savedCommunicationTypeDto);
+ }
+
+ @PutMapping("/{uuid}")
+ @ApiOperation(value = "Ändern eines Kommunikationstyps")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Kommunikationstyp wurde aktualisiert"),
+ @ApiResponse(code = 400, message = "Ungültige Eingabe"),
+ @ApiResponse(code = 404, message = "Nicht gefunden")})
+ public ResponseEntity updateCommunicationType(@PathVariable UUID uuid, @Validated @RequestBody CommunicationTypeDto communicationTypeDto) {
+
+ if (!communicationTypeDto.getUuid().equals(uuid)) {
+ // TODO: Msg extrahieren
+ throw new BadRequestException("Die Id des Pfades stimmt nicht mit der des Objekts überein");
+ }
+
+ communicationTypeService.updateCommunicationType(communicationTypeDto);
+ return ResponseEntity.ok().build();
+ }
+
+ @DeleteMapping("/{uuid}")
+ @ResponseStatus(HttpStatus.OK)
+ @ApiOperation(value = "Kommunikationstyp löschen")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "Erfolgreich durchgeführt"),
+ @ApiResponse(code = 400, message = "Ungültige Anfrage"),
+ @ApiResponse(code = 404, message = "Nicht gefunden")})
+ public void removeComunicationType(@PathVariable UUID uuid) {
+ communicationTypeService.removeCommunicationType(uuid);
+ }
+}
+
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/mapper/CommunicationTypeMapper.java b/src/main/java/org/eclipse/openk/contactbasedata/mapper/CommunicationTypeMapper.java
index a6ab66b..958fd5d 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/mapper/CommunicationTypeMapper.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/mapper/CommunicationTypeMapper.java
@@ -16,11 +16,14 @@
import org.eclipse.openk.contactbasedata.model.RefCommunicationType;
import org.eclipse.openk.contactbasedata.viewmodel.CommunicationDto;
+import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CommunicationTypeMapper {
- CommunicationDto toCommunicationTypeDto(RefCommunicationType refCommunicationType);
+ CommunicationTypeDto toCommunicationTypeDto(RefCommunicationType refCommunicationType);
+
+ RefCommunicationType toRefCommunicationType(CommunicationTypeDto communicationTypeDto);
}
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 80c5cca..87aba2c 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/RefCommunicationType.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/RefCommunicationType.java
@@ -31,6 +31,8 @@
private UUID uuid;
private String type;
private String description;
+ private boolean editable;
+ private boolean mappingLdap;
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/AddressRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/AddressRepository.java
new file mode 100644
index 0000000..085eb00
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/AddressRepository.java
@@ -0,0 +1,31 @@
+/*
+ *******************************************************************************
+ * 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.repository;
+
+import org.eclipse.openk.contactbasedata.model.RefSalutation;
+import org.eclipse.openk.contactbasedata.model.TblAddress;
+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;
+
+public interface AddressRepository extends JpaRepository<TblAddress, Long> {
+
+ @Query("select a from TblAddress a where a.tblContact.uuid = ?1")
+ List< TblAddress > findByTblContactUuid(final UUID contactUuid);
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationTypeRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationTypeRepository.java
new file mode 100644
index 0000000..61eed73
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationTypeRepository.java
@@ -0,0 +1,15 @@
+package org.eclipse.openk.contactbasedata.repository;
+
+import org.eclipse.openk.contactbasedata.model.RefCommunicationType;
+import org.eclipse.openk.contactbasedata.model.TblExternalPerson;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.Optional;
+import java.util.UUID;
+
+public interface CommunicationTypeRepository extends JpaRepository<RefCommunicationType, Long > {
+
+ Optional< RefCommunicationType > findByUuid(final UUID communicationTypeUuid);
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java
new file mode 100644
index 0000000..e03ec03
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/AddressService.java
@@ -0,0 +1,55 @@
+/*
+ *******************************************************************************
+ * 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.exceptions.BadRequestException;
+import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
+import org.eclipse.openk.contactbasedata.mapper.AddressMapper;
+import org.eclipse.openk.contactbasedata.mapper.SalutationMapper;
+import org.eclipse.openk.contactbasedata.model.RefSalutation;
+import org.eclipse.openk.contactbasedata.model.TblAddress;
+import org.eclipse.openk.contactbasedata.repository.AddressRepository;
+import org.eclipse.openk.contactbasedata.repository.SalutationRepository;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.SalutationDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+@Log4j2
+@Service
+public class AddressService {
+ @Autowired
+ private AddressRepository addressRepository;
+
+ @Autowired
+ AddressMapper addressMapper;
+
+
+ public List<AddressDto> getAddressesByContactUuid(UUID contactUuid) {
+ List<TblAddress> tblAddressList = addressRepository
+ .findByTblContactUuid(contactUuid);
+
+ return tblAddressList.stream().map(addressMapper::toAddressDto).collect(Collectors.toList());
+ }
+
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java
new file mode 100644
index 0000000..ddc7a6c
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeService.java
@@ -0,0 +1,80 @@
+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.CommunicationTypeMapper;
+import org.eclipse.openk.contactbasedata.mapper.ContactMapper;
+import org.eclipse.openk.contactbasedata.mapper.ExternalPersonMapper;
+import org.eclipse.openk.contactbasedata.model.*;
+import org.eclipse.openk.contactbasedata.repository.*;
+import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
+import org.eclipse.openk.contactbasedata.viewmodel.ExternalPersonDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+@Log4j2
+@Service
+public class CommunicationTypeService {
+ @Autowired
+ private CommunicationTypeRepository communicationTypeRepository;
+
+ @Autowired
+ private CommunicationTypeMapper communicationTypeMapper;
+
+
+ public CommunicationTypeDto findCommunicationType(UUID communicationTypeUuid) {
+ return communicationTypeMapper.toCommunicationTypeDto(
+ communicationTypeRepository.findByUuid(communicationTypeUuid).orElseThrow(NotFoundException::new)
+ );
+ }
+
+ public List<CommunicationTypeDto> findCommunicationTypes() {
+ return communicationTypeRepository.findAll().stream()
+ .map(communicationTypeMapper::toCommunicationTypeDto)
+ .collect(Collectors.toList());
+ }
+
+ public CommunicationTypeDto insertCommunicationType(CommunicationTypeDto communicationTypeDto) {
+
+ RefCommunicationType communicationTypeToSave = communicationTypeMapper.toRefCommunicationType(communicationTypeDto);
+ communicationTypeToSave.setUuid(UUID.randomUUID());
+
+ RefCommunicationType savedCommunicationType = communicationTypeRepository.save(communicationTypeToSave);
+
+ return communicationTypeMapper.toCommunicationTypeDto(savedCommunicationType);
+ }
+
+
+ public CommunicationTypeDto updateCommunicationType(CommunicationTypeDto communicationTypeDto){
+ RefCommunicationType communicationTypeUpdated;
+
+ RefCommunicationType existingCommunicationType = communicationTypeRepository
+ .findByUuid(communicationTypeDto.getUuid())
+ .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing"));
+
+ RefCommunicationType communicationTypeToSave = communicationTypeMapper.toRefCommunicationType(communicationTypeDto);
+ communicationTypeToSave.setId(existingCommunicationType.getId());
+
+ communicationTypeUpdated = communicationTypeRepository.save(communicationTypeToSave);
+
+ return communicationTypeMapper.toCommunicationTypeDto(communicationTypeUpdated);
+ }
+
+
+ public void removeCommunicationType(UUID uuid) {
+ RefCommunicationType existingCommunicationType = communicationTypeRepository.findByUuid(uuid)
+ .orElseThrow( () -> new NotFoundException("communication.type.uuid.not.existing"));
+
+ communicationTypeRepository.delete(existingCommunicationType);
+ }
+
+}
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 df897cd..6ba6e67 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/ExternalPersonService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ExternalPersonService.java
@@ -79,29 +79,34 @@
TblExternalPerson externalPersonUpdated;
//Externe Person holen
- //TODO: Fehlermeldung mit message!
TblExternalPerson existingExternalPerson = externalPersonRepository
.findByTblContactUuid(externalPersonDto.getContactId())
- .orElseThrow(() -> new NotFoundException("Der angegebene Kontakt existiert nicht"));
+ .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+
+// TblExternalPerson externalPersonToSave = externalPersonMapper.toTblExternalPerson(externalPersonDto);
+// externalPersonToSave.setId(existingExternalPerson.getId());
existingExternalPerson.setLastName(externalPersonDto.getLastName());
existingExternalPerson.setFirstName(externalPersonDto.getFirstName());
existingExternalPerson.setTitle(externalPersonDto.getTitle());
setFromExternalPersonDto( existingExternalPerson, externalPersonDto );
+ //setFromExternalPersonDto( externalPersonToSave, externalPersonDto );
externalPersonUpdated = externalPersonRepository.save(existingExternalPerson);
+ //externalPersonUpdated = externalPersonRepository.save(externalPersonToSave);
return externalPersonMapper.toExternalPersonDto(externalPersonUpdated);
}
private void setFromExternalPersonDto( TblExternalPerson destTblExternalPerson, ExternalPersonDto sourceDto ) {
+
RefSalutation salutationUpdated = salutationRepository
.findByUuid(sourceDto.getSalutationId())
- .orElseThrow(() -> new NotFoundException("Anrede wurde nicht gefunden"));
- // TODO: Nachricht auslagern
+ .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
+
RefPersonType personTypeUpdated = personTypeRepository
.findByUuid(sourceDto.getPersonTypeId())
- .orElseThrow(() -> new NotFoundException("Persontyp wurde nicht gefunden"));
+ .orElseThrow(() -> new NotFoundException("person.type.uuid.not.existing"));
destTblExternalPerson.setSalutation(salutationUpdated);
destTblExternalPerson.setRefPersonType(personTypeUpdated);
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 87e04e8..9c615d0 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
@@ -48,7 +48,7 @@
public SalutationDto getSalutationByUuid(UUID salutationUuid) {
RefSalutation refSalutation = salutationRepository
.findByUuid(salutationUuid)
- .orElseThrow(() -> new NotFoundException("salutation.not.found"));
+ .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
return salutationMapper.toSalutationDto(refSalutation);
}
@@ -67,7 +67,7 @@
RefSalutation salutationToSave = salutationMapper.toRefSalutation(salutationDto);
RefSalutation existingSalutation = salutationRepository
.findByUuid(salutationDto.getUuid())
- .orElseThrow(() -> new NotFoundException("salutation.not.found"));
+ .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
salutationToSave.setId(existingSalutation.getId());
salutationUpdated = salutationRepository.save(salutationToSave);
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 ff1bda2..c861000 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CommunicationTypeDto.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/CommunicationTypeDto.java
@@ -10,4 +10,6 @@
private UUID uuid;
private String type;
private String description;
+ private boolean editable;
+ private boolean mappingLdap;
}
diff --git a/src/main/resources/db/migration/V0_5__CREATE_CBD_DB.sql b/src/main/resources/db/migration/V0_5__CREATE_CBD_DB.sql
new file mode 100644
index 0000000..c96c2c0
--- /dev/null
+++ b/src/main/resources/db/migration/V0_5__CREATE_CBD_DB.sql
@@ -0,0 +1,641 @@
+-----------------------------------------------------------------------------------
+-- *******************************************************************************
+-- * 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;
+
+-- ---------------------------------------------
+-- 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),
+ 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) VALUES ( 'ae3f2ec1-ccc5-4269-a48f-dd40e37fa14e', 'COM', 'company 1' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( 'fc7f598b-0d51-46bb-9563-99851fe6a3ad', 'COM', 'company 2 ' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( '556b91be-6d57-432f-93ed-65604dd6e5cd', 'C_P', 'contact person 1' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( '116380e3-25c5-4179-b40a-8abebe10fe07', 'C_P', 'contact person 2' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( '7782179b-fb79-4370-8f71-f4c71470d006', 'I_P', 'internal person 1' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( '8963aa38-d021-4dc9-bd70-d3734ccd20c4', 'I_P', 'internal person 2' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( 'c862d604-5766-43d6-a7e8-a4bac2bd01e1', 'E_P', 'external person 1' );
+INSERT INTO public.TBL_CONTACT (UUID, CONTACT_TYPE, NOTE) VALUES ( 'fa3d981b-a7d6-4965-a623-cdbc69404153', 'E_P', 'exernal person 2' );
+
+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);
+
+
+-- ---------------------------------------------
+-- 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,
+ 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) VALUES ( '4757ca3a-72c2-4f13-a2f6-ce092e3eadf4', 'Mail', 'Mailadresse', false, true );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP) VALUES ( '77028572-ff57-4c1d-999a-78fa3fcbc1cd', 'Mobil', '', false, true );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP) VALUES ( 'f7d5b343-00c2-4d7f-8e03-009aad3d90f7', 'Festnetz', '', true, false );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP) VALUES ( '2bfe40f9-c4eb-4d2e-855f-6b0883912846', 'Fax', '', true, false );
+INSERT INTO public.REF_COMMUNICATION_TYPE (UUID, TYPE, DESCRIPTION, EDITABLE, MAPPING_LDAP) VALUES ( 'd00d1a61-c8e7-43b2-959f-66e986731441', 'WhatsApp', '', true, 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),
+
+ 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) VALUES ( '25f6d7cc-b168-4dd5-a36d-6f14b2f956e9', 2, 2, 'bitte melden Sie sich bei uns');
+INSERT INTO public.TBL_COMMUNICATION (UUID, FK_CONTACT_ID, FK_COMMUNICATION_TYPE, COMMUNICATION_DATA) VALUES ( 'a5fa380e-8f33-4ea7-9416-e03d11b91cae', 1, 3, 'bitte melden zwecks Terminabstimmung');
+
+
+-- ---------------------------------------------
+-- 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 );
+
+
+-- ---------------------------------------------
+-- 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 NOT 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);
+
+
+-- ---------------------------------------------
+-- 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),
+ SID 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_sid ON public.TBL_INTERNAL_PERSON ( SID 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, SID, 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, SID, USER_REF, FK_CONTACT_ID) VALUES ( 'Bernhardt', 'Iffland', '', 2, 2,'Kreativ', '4124e4e7-3488-4492-bf39-75e6a23a1c1a', 'BIFFL', 6);
+
+-- -------------------------------------
+-- 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
+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,
+ p.last_name || ' ' || p.first_name || ' [' || 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,
+ last_name || ' ' || 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,
+ last_name || ' ' || 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,
+ 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,
+
+ 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.id = c.id
+ AND com.fk_communication_type=(
+ SELECT ct.id FROM ref_communication_type ct WHERE UPPER(ct.type) LIKE 'MAIL' LIMIT 1 ) ) ;
+
+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/main/resources/messages.properties b/src/main/resources/messages.properties
index d64a217..b4541ed 100644
--- a/src/main/resources/messages.properties
+++ b/src/main/resources/messages.properties
@@ -1,5 +1,9 @@
#Fehlermeldungen
invalid.uuid.path.object=Die UUID entspricht nicht der UUID des \u00fcbergebenen Datensatzes.
+address.not.found=Adresse wurde nicht gefunden
salutation.not.found=Anrede wurde nicht gefunden
salutation.uuid.not.existing=Die \u00fcbergebene UUID einer Anrede existiert nicht
+communication.type.uuid.not.existing= Die \u00fcbergebene UUID eines Kommunikationstyps existiert nicht
+contact.uuid.not.existing= Die \u00fcbergebene UUID eines Kontaktes existiert nicht
+person.type.uuid.not.existing= Die \u00fcbergebene UUID eines Personentyps existiert nicht
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 b1b4254..ed8c894 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
@@ -40,6 +40,12 @@
SalutationMapper salutationMapper() { return new SalutationMapperImpl(); }
@Bean
+ AddressMapper addressMapper() { return new AddressMapperImpl(); }
+
+ @Bean
+ CommunicationTypeMapper communicationTypeMapper() { return new CommunicationTypeMapperImpl(); }
+
+ @Bean
public VersionService myVersionService() {
return new VersionService();
}
@@ -54,5 +60,11 @@
public SalutationService mySalutationService() { return new SalutationService(); }
@Bean
+ public AddressService myAddressService() { return new AddressService(); }
+
+ @Bean
+ public CommunicationTypeService myCommunicationTypeService() { return new CommunicationTypeService(); }
+
+ @Bean
public BaseContactService myBaseContactService() { return new BaseContactService(); }
}
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/AddressControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/AddressControllerTest.java
new file mode 100644
index 0000000..8d1ff3f
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/AddressControllerTest.java
@@ -0,0 +1,60 @@
+/*
+ *******************************************************************************
+ * 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.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.eclipse.openk.contactbasedata.ContactBaseDataApplication;
+import org.eclipse.openk.contactbasedata.service.AddressService;
+import org.eclipse.openk.contactbasedata.service.SalutationService;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.SalutationDto;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+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.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+@SpringBootTest(classes = ContactBaseDataApplication.class)
+@AutoConfigureMockMvc
+public class AddressControllerTest {
+
+ @MockBean
+ private AddressService addressService;
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ public void shouldReturnAddressesForAContact() throws Exception {
+ List<AddressDto> listDtos = MockDataHelper.mockAddressDtoList();
+
+ when(addressService.getAddressesByContactUuid(any(UUID.class))).thenReturn(listDtos);
+
+ mockMvc.perform(get("/contacts/{uuid}/addresses", UUID.randomUUID()))
+ .andExpect(status().is2xxSuccessful())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java
new file mode 100644
index 0000000..d3bb418
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/CommunicationTypeControllerTest.java
@@ -0,0 +1,121 @@
+/*
+ *******************************************************************************
+ * 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.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.eclipse.openk.contactbasedata.ContactBaseDataApplication;
+import org.eclipse.openk.contactbasedata.service.CommunicationTypeService;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+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.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+
+
+
+@SpringBootTest(classes = ContactBaseDataApplication.class)
+@AutoConfigureMockMvc
+public class CommunicationTypeControllerTest {
+
+ @MockBean
+ private CommunicationTypeService communicationTypeService;
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ public void shouldReturnAllCommunicationTypes() throws Exception {
+ List<CommunicationTypeDto> ctDtos = MockDataHelper.mockCommunicationTypeDtoList();
+
+ when(communicationTypeService.findCommunicationTypes()).thenReturn(ctDtos);
+
+ mockMvc.perform(get("/communication-types"))
+ .andExpect(status().is2xxSuccessful())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+ @Test
+ public void shouldReturnSingleCommunicationType() throws Exception {
+ CommunicationTypeDto communicationTypeDto = MockDataHelper.mockCommunicationTypeDto();
+
+ when(communicationTypeService.findCommunicationType(any(UUID.class))).thenReturn(communicationTypeDto);
+
+ mockMvc.perform(get("/communication-types/37454f86-2006-11ea-978f-2e728ce88125"))
+ .andExpect(status().is2xxSuccessful())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+ @Test
+ public void shouldInsertCommunicationType() throws Exception {
+ CommunicationTypeDto communicationTypeDto = MockDataHelper.mockCommunicationTypeDto();
+ communicationTypeDto.setType("Trommel");
+ communicationTypeDto.setDescription("Djembe");
+
+ when(communicationTypeService.insertCommunicationType(any(CommunicationTypeDto.class)))
+ .thenReturn(communicationTypeDto);
+
+ mockMvc.perform(post("/communication-types")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(new ObjectMapper().writeValueAsString(communicationTypeDto)))
+ .andExpect(jsonPath("$.type", Matchers.is("Trommel")))
+ .andExpect(jsonPath("$.description", Matchers.is("Djembe" )));
+ }
+
+ @Test
+ public void shouldUpdateCommunicationType() throws Exception {
+ CommunicationTypeDto dto = MockDataHelper.mockCommunicationTypeDto();
+
+ when( communicationTypeService.updateCommunicationType(any(CommunicationTypeDto.class))).thenReturn(dto);
+
+ mockMvc.perform(put("/communication-types/{uuid}", dto.getUuid().toString())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(new ObjectMapper().writeValueAsString(dto)))
+ .andExpect(status().is2xxSuccessful());
+ }
+
+ @Test
+ public void shouldNotUpdateCommunicationTypeDueToError() throws Exception {
+ CommunicationTypeDto communicationTypeDto = MockDataHelper.mockCommunicationTypeDto();
+ communicationTypeDto.setUuid(UUID.randomUUID());
+
+ when( communicationTypeService.updateCommunicationType(any(CommunicationTypeDto.class))).thenReturn(communicationTypeDto);
+
+ // use different UUIDs for path and object
+ mockMvc.perform(put("/communication-types/{uuid}", UUID.randomUUID().toString())
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(new ObjectMapper().writeValueAsString(communicationTypeDto)))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void shouldDeleteCommunicationType() throws Exception {
+ mockMvc.perform(delete("/communication-types/05ff2344-20a5-11ea-978f-2e728ce88125")
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().is2xxSuccessful());
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/SalutationControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/SalutationControllerTest.java
index edb8e5d..1a6aea0 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/SalutationControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/SalutationControllerTest.java
@@ -124,7 +124,6 @@
.andExpect(status().isBadRequest());
}
-
@Test
public void shouldDeleteSalutation() throws Exception {
mockMvc.perform(delete("/salutations/05ff2344-20a5-11ea-978f-2e728ce88125")
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/AddressServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/AddressServiceTest.java
new file mode 100644
index 0000000..19b25c0
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/AddressServiceTest.java
@@ -0,0 +1,64 @@
+/*
+ *******************************************************************************
+ * 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.model.RefSalutation;
+import org.eclipse.openk.contactbasedata.model.TblAddress;
+import org.eclipse.openk.contactbasedata.repository.AddressRepository;
+import org.eclipse.openk.contactbasedata.repository.SalutationRepository;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.SalutationDto;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+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.List;
+import java.util.Optional;
+import java.util.UUID;
+
+import static org.hibernate.validator.internal.util.Contracts.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@DataJpaTest
+@ContextConfiguration(classes = {TestConfiguration.class})
+
+public class AddressServiceTest {
+ @Qualifier("myAddressService")
+ @Autowired
+ private AddressService addressService;
+
+ @MockBean
+ private AddressRepository addressRepository;
+
+ @Test
+ public void shouldReturnAddressesByContactUuid() {
+
+ List<TblAddress> listTblAddresses = MockDataHelper.mockTblAddressList();
+ when(addressRepository.findByTblContactUuid( any(UUID.class)) ).thenReturn(listTblAddresses);
+
+ List<AddressDto> dtoList = addressService.getAddressesByContactUuid(UUID.randomUUID());
+ assertEquals(dtoList.size(), 2 );
+ }
+}
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeServiceTest.java
new file mode 100644
index 0000000..1121c09
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/CommunicationTypeServiceTest.java
@@ -0,0 +1,126 @@
+/*
+ *******************************************************************************
+ * 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.model.RefCommunicationType;
+import org.eclipse.openk.contactbasedata.model.RefSalutation;
+import org.eclipse.openk.contactbasedata.repository.CommunicationTypeRepository;
+import org.eclipse.openk.contactbasedata.repository.SalutationRepository;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
+import org.eclipse.openk.contactbasedata.viewmodel.SalutationDto;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+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.List;
+import java.util.Optional;
+import java.util.UUID;
+
+import static org.hibernate.validator.internal.util.Contracts.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@DataJpaTest
+@ContextConfiguration(classes = {TestConfiguration.class})
+
+public class CommunicationTypeServiceTest {
+ @Qualifier("myCommunicationTypeService")
+ @Autowired
+ private CommunicationTypeService communicationTypeService;
+
+ @MockBean
+ private CommunicationTypeRepository communicationTypeRepository;
+
+ @Test
+ public void shouldFindAllCommunicationTypes() {
+ List<RefCommunicationType> rct = MockDataHelper.mockRefCommunicationTypeList();
+ when(communicationTypeRepository.findAll()).thenReturn(rct);
+ List<CommunicationTypeDto> retVals = communicationTypeService.findCommunicationTypes();
+
+ assertEquals(rct.size(), retVals.size());
+ assertEquals(rct.size(), 3);
+ assertEquals(rct.get(1).getUuid(), retVals.get(1).getUuid());
+ }
+
+
+ @Test
+ public void shouldReturnCommunicationTypeByUuid() {
+
+ RefCommunicationType rct = MockDataHelper.mockRefCommunicationType();
+ rct.setType("Testtyp");
+ when( communicationTypeRepository.findByUuid( any(UUID.class)) ).thenReturn(Optional.of(rct));
+
+ CommunicationTypeDto communicationTypeDto = communicationTypeService.findCommunicationType(UUID.randomUUID());
+ assertEquals( communicationTypeDto.getUuid(), rct.getUuid() );
+ assertEquals( communicationTypeDto.getType(), rct.getType() );
+ }
+
+ @Test
+ public void shouldInsertCommunicationType(){
+ RefCommunicationType rfc = MockDataHelper.mockRefCommunicationType();
+
+ rfc.setUuid(UUID.fromString("b1a9b6de-3129-11ea-978f-2e728ce88125"));
+ rfc.setType("Brieftaube");
+ rfc.setDescription("Ringeltaube");
+
+ CommunicationTypeDto communicationTypeDto = MockDataHelper.mockCommunicationTypeDto();
+ communicationTypeDto.setUuid(null);
+
+ when( communicationTypeRepository.save( any( RefCommunicationType.class) )).thenReturn(rfc);
+
+ CommunicationTypeDto savedCommunicationTypeDto = communicationTypeService.insertCommunicationType(communicationTypeDto);
+ assertEquals("Brieftaube", savedCommunicationTypeDto.getType());
+ assertNotNull( savedCommunicationTypeDto.getUuid());
+ }
+
+ @Test
+ public void shouldUpdateCommunicationType() {
+
+ RefCommunicationType rfc = MockDataHelper.mockRefCommunicationType();
+ rfc.setType("Rauchzeichen");
+
+ CommunicationTypeDto communicationTypeDto = MockDataHelper.mockCommunicationTypeDto();
+ communicationTypeDto.setType("Leuchtfeuer");
+
+ when( communicationTypeRepository.findByUuid( any(UUID.class)) ).thenReturn(Optional.of(rfc));
+ when( communicationTypeRepository.save( any(RefCommunicationType.class)) ).thenReturn(rfc);
+ CommunicationTypeDto communicationTypeDtoUpdated = communicationTypeService.updateCommunicationType(communicationTypeDto);
+
+ assertEquals(rfc.getUuid(), communicationTypeDtoUpdated.getUuid());
+ assertEquals("Rauchzeichen", communicationTypeDtoUpdated.getType());
+ }
+
+
+ @Test
+ public void shouldDeleteCommunicationType() {
+
+ RefCommunicationType rft = MockDataHelper.mockRefCommunicationType();
+
+ when(communicationTypeRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(rft));
+ Mockito.doNothing().when(communicationTypeRepository).delete( isA( RefCommunicationType.class ));
+ communicationTypeService.removeCommunicationType(rft.getUuid());
+
+ Mockito.verify(communicationTypeRepository, times(1)).delete( rft );
+ }
+}
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 401bb41..d7690d2 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
@@ -16,6 +16,8 @@
import org.eclipse.openk.contactbasedata.constants.Constants;
import org.eclipse.openk.contactbasedata.model.*;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.CommunicationTypeDto;
import org.eclipse.openk.contactbasedata.viewmodel.ExternalPersonDto;
import org.eclipse.openk.contactbasedata.viewmodel.SalutationDto;
import org.eclipse.openk.contactbasedata.viewmodel.VersionDto;
@@ -23,10 +25,7 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
public class MockDataHelper {
@@ -144,4 +143,162 @@
pt.setType("ehrenmann");
return pt;
}
+
+ public static TblAddress mockTblAddress(){
+ TblAddress tblAddress = new TblAddress();
+
+ tblAddress.setCommunity("Fischland");
+ tblAddress.setCommunitySuffix("-");
+ tblAddress.setHousenumber("13");
+ tblAddress.setId(5L);
+ tblAddress.setIsMainAddress(false);
+ tblAddress.setLatitude("52N");
+ tblAddress.setLongitude("2E");
+ tblAddress.setNote("-");
+ tblAddress.setPostcode("67890");
+ //tblAddress.setRefAddressType();
+ tblAddress.setStreet("Moosrosenweg");
+ //tblAddress.setTblContact();
+ tblAddress.setUrlMap("-");
+ tblAddress.setUuid(UUID.fromString("f34dfffc-314a-11ea-978f-2e728ce88125"));
+ tblAddress.setWgs_84_zone("-");
+
+ return tblAddress;
+ }
+
+ public static AddressDto mockAddressDto(){
+ AddressDto addressDto = new AddressDto();
+
+ addressDto.setCommunity("Fischland");
+ addressDto.setCommunitySuffix("-");
+ addressDto.setHousenumber("13");
+ addressDto.setIsMainAddress(false);
+ addressDto.setLatitude("52N");
+ addressDto.setLongitude("2E");
+ addressDto.setNote("-");
+ addressDto.setPostcode("67890");
+ //addressDto.setRefAddressType();
+ addressDto.setStreet("Moosrosenweg");
+ //addressDto.setTblContact();
+ addressDto.setUrlMap("-");
+ addressDto.setUuid(UUID.fromString("f34dfffc-314a-11ea-978f-2e728ce88125"));
+ addressDto.setWgs84Zone("-");
+
+ return addressDto;
+ }
+
+ public static List<AddressDto> mockAddressDtoList(){
+
+ List<AddressDto> list = new ArrayList<>();
+
+ AddressDto addressDto1 = mockAddressDto();
+
+ AddressDto addressDto2 = new AddressDto();
+ addressDto2.setCommunity("Pusemuckel");
+ addressDto2.setCommunitySuffix("-");
+ addressDto2.setHousenumber("17");
+ addressDto2.setIsMainAddress(false);
+ addressDto2.setLatitude("51N");
+ addressDto2.setLongitude("3E");
+ addressDto2.setNote("-");
+ addressDto2.setPostcode("87655");
+ //addressDto.setRefAddressType();
+ addressDto2.setStreet("Birkenweg");
+ //addressDto.setTblContact();
+ addressDto2.setUrlMap("-");
+ addressDto2.setUuid(UUID.fromString("7dff534c-314d-11ea-978f-2e728ce88125"));
+ addressDto2.setWgs84Zone("-");
+
+ list.add(addressDto1);
+ list.add(addressDto2);
+
+ return list;
+ }
+
+ public static List<TblAddress> mockTblAddressList(){
+
+ List<TblAddress> list = new ArrayList<>();
+
+ TblAddress tblAddressDto1 = mockTblAddress();
+
+ TblAddress tblAddressDto2 = new TblAddress();
+ tblAddressDto2.setCommunity("Pusemuckel");
+ tblAddressDto2.setCommunitySuffix("-");
+ tblAddressDto2.setHousenumber("17");
+ tblAddressDto2.setIsMainAddress(false);
+ tblAddressDto2.setLatitude("51N");
+ tblAddressDto2.setLongitude("3E");
+ tblAddressDto2.setNote("-");
+ tblAddressDto2.setPostcode("87655");
+ //tblAddressDto2.setRefAddressType();
+ tblAddressDto2.setStreet("Birkenweg");
+ //tblAddressDto2.setTblContact();
+ tblAddressDto2.setUrlMap("-");
+ tblAddressDto2.setUuid(UUID.fromString("7dff534c-314d-11ea-978f-2e728ce88125"));
+ tblAddressDto2.setWgs_84_zone("-");
+
+ list.add(tblAddressDto1);
+ list.add(tblAddressDto2);
+
+ return list;
+ }
+
+ public static RefCommunicationType mockRefCommunicationType(){
+ RefCommunicationType communicationType = new RefCommunicationType();
+ communicationType.setId(2L);
+ communicationType.setUuid(UUID.randomUUID());
+ communicationType.setDescription("Fax");
+ communicationType.setType("Fax");
+ communicationType.setEditable(true);
+ communicationType.setMappingLdap(false);
+
+ return communicationType;
+ }
+
+ public static CommunicationTypeDto mockCommunicationTypeDto(){
+ CommunicationTypeDto communicationTypeDto = new CommunicationTypeDto();
+ communicationTypeDto.setUuid(UUID.randomUUID());
+ communicationTypeDto.setDescription("Fax");
+ communicationTypeDto.setType("Fax");
+ communicationTypeDto.setEditable(true);
+ communicationTypeDto.setMappingLdap(false);
+
+ return communicationTypeDto;
+ }
+
+ public static List<CommunicationTypeDto> mockCommunicationTypeDtoList(){
+
+ CommunicationTypeDto ctDto1 = mockCommunicationTypeDto();
+ CommunicationTypeDto ctDto2 = mockCommunicationTypeDto();
+ ctDto2.setDescription("Mobil");
+ ctDto2.setType("Mobil");
+ CommunicationTypeDto ctDto3 = mockCommunicationTypeDto();
+ ctDto3.setDescription("Persönlich");
+ ctDto3.setType("Persönlich");
+
+ List<CommunicationTypeDto> listCtDto = new ArrayList<>();
+ listCtDto.add(ctDto1);
+ listCtDto.add(ctDto2);
+ listCtDto.add(ctDto3);
+
+ return listCtDto;
+ }
+
+ public static List<RefCommunicationType> mockRefCommunicationTypeList(){
+
+ RefCommunicationType ct1 = mockRefCommunicationType();
+ RefCommunicationType ct2 = mockRefCommunicationType();
+ ct2.setDescription("Mobil");
+ ct2.setType("Mobil");
+ RefCommunicationType ct3 = mockRefCommunicationType();
+ ct3.setDescription("Persönlich");
+ ct3.setType("Persönlich");
+
+ List<RefCommunicationType> listCt = new ArrayList<>();
+ listCt.add(ct1);
+ listCt.add(ct2);
+ listCt.add(ct3);
+
+ return listCt;
+ }
}