merge conflicts resolved V0_9__CREATE_CBD_DB.sql
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/AssignmentModulContactController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/AssignmentModulContactController.java
new file mode 100644
index 0000000..87ae6d1
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/AssignmentModulContactController.java
@@ -0,0 +1,109 @@
+/*
+ *******************************************************************************
+ * 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.exceptions.BadRequestException;
+import org.eclipse.openk.contactbasedata.service.AddressService;
+import org.eclipse.openk.contactbasedata.service.AssignmentModulContactService;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.AssignmentModulContactDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.annotation.Secured;
+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("/contacts")
+public class AssignmentModulContactController {
+    @Autowired
+    private AssignmentModulContactService assignmentModulContactService;
+
+    @GetMapping ("/{contactUuid}/assignments")
+    @Secured({"ROLE_KON-READER", "ROLE_KON-WRITER", "ROLE_KON-ADMIN"})
+    @ApiOperation(value = "Anzeigen aller Zuordnungen Kontakt:Modul")
+    @ApiResponses(value = {
+            @ApiResponse(code = 400, message = "Ungültige Anfrage."),
+            @ApiResponse(code = 200, message = "Suche durchgeführt")})
+    @ResponseStatus(HttpStatus.OK)
+    public List<AssignmentModulContactDto> getAssignment(
+             @PathVariable UUID contactUuid) {
+        return assignmentModulContactService.getAssignments(contactUuid);
+    }
+
+
+    @PostMapping("/{contactUuid}/assignments")
+    @ApiOperation(value = "Anlegen einer neuen Zuordnung Kontakt:Modul")
+    @ApiResponses(value = {
+            @ApiResponse(code = 200, message = "Zuordnung erfolgreich angelegt"),
+            @ApiResponse(code = 500, message = "Konnte nicht durchgeführt werden")
+    })
+    public ResponseEntity<AssignmentModulContactDto> insertAssignment(
+            @PathVariable UUID contactUuid,
+            @Validated @RequestBody AssignmentModulContactDto assignmentModulContactDto) {
+        if (!contactUuid.equals(assignmentModulContactDto.getContactUuid())) {
+            throw new BadRequestException("invalid.uuid.path.object");
+        }
+        AssignmentModulContactDto savedAssignment = assignmentModulContactService.insertAssignment(contactUuid, assignmentModulContactDto);
+        URI location = ServletUriComponentsBuilder
+                .fromCurrentRequestUri()
+                .path("/{uuid}")
+                .buildAndExpand(savedAssignment.getUuid())
+                .toUri();
+        return ResponseEntity.created(location).body(savedAssignment);
+    }
+
+
+    @PutMapping("/{contactUuid}/assignments/{assignmentUuid}")
+    @ApiOperation(value = "Ändern einer Zuordnung Kontakt:Modul")
+    @ApiResponses(value = {
+            @ApiResponse(code = 404, message = "Zuordnung nicht gefunden."),
+            @ApiResponse(code = 400, message = "Ungültige Anfrage."),
+            @ApiResponse(code = 200, message = "Zuordnung erfolgreich geändert.")})
+    public ResponseEntity updateAssignment(
+            @PathVariable UUID contactUuid,
+            @PathVariable UUID assignmentUuid,
+            @Validated @RequestBody AssignmentModulContactDto assignmentDto) {
+        if (!assignmentUuid.equals(assignmentDto.getUuid())) {
+            throw new BadRequestException("invalid.uuid.path.object");
+        }
+        assignmentModulContactService.updateAssignment(contactUuid, assignmentDto);
+        return ResponseEntity.ok().build();
+    }
+
+    @DeleteMapping("{contactUuid}/assignments/{assignmentUuid}")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiOperation(value = "Eine bestimmte Zuordnung eines bestimmten Kontakts löschen")
+    @ApiResponses(value = {
+            @ApiResponse(code = 204, message = "Erfolgreich gelöscht"),
+            @ApiResponse(code = 400, message = "Ungültige Anfrage"),
+            @ApiResponse(code = 404, message = "Nicht gefunden")})
+    public void deleteAssignment(@PathVariable("contactUuid") UUID contactUuid,
+                              @PathVariable("assignmentUuid") UUID assignmentUuid) {
+        assignmentModulContactService.deleteAssignment(contactUuid, assignmentUuid);
+    }
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/mapper/AssignmentModulContactMapper.java b/src/main/java/org/eclipse/openk/contactbasedata/mapper/AssignmentModulContactMapper.java
new file mode 100644
index 0000000..c3a67ca
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/mapper/AssignmentModulContactMapper.java
@@ -0,0 +1,36 @@
+/*
+ *******************************************************************************
+ * 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.mapper;
+
+import org.eclipse.openk.contactbasedata.model.TblAddress;
+import org.eclipse.openk.contactbasedata.model.TblAssignmentModulContact;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.AssignmentModulContactDto;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Mappings;
+import org.mapstruct.ReportingPolicy;
+
+@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
+public interface AssignmentModulContactMapper {
+
+    @Mappings({
+            @Mapping( source="tblContact.uuid", target="contactUuid"),
+    })
+    AssignmentModulContactDto toAssignmentModulContactDto(TblAssignmentModulContact tblAssignmentModulContact);
+
+    TblAssignmentModulContact toTblAssignmentModulContact(AssignmentModulContactDto assignmentModulContactDto);
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java b/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java
new file mode 100644
index 0000000..4613219
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java
@@ -0,0 +1,44 @@
+/*
+    *******************************************************************************
+    * 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.model;
+
+import lombok.Data;
+import javax.persistence.*;
+import java.util.Date;
+import java.util.UUID;
+
+@Data
+@Entity
+public class TblAssignmentModulContact {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE,  generator = "tbl_assignment_modul_contact_id_seq")
+    @SequenceGenerator(name = "tbl_assignment_modul_contact_id_seq", sequenceName = "tbl_assignment_modul_contact_id_seq", allocationSize = 1)
+    @Column(name = "id", updatable = false)
+    private Long id;
+    private UUID uuid;
+    private String modulName;
+    private Date assignmentDate;
+    private Date expiringDate;
+    private Date deletionLockUntil;
+    private String assignmentNote;
+
+    @ManyToOne
+    @JoinColumn( name = "fk_contact_id")
+    private TblContact tblContact;
+
+
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/AssignmentModulContactRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/AssignmentModulContactRepository.java
new file mode 100644
index 0000000..3a41d6e
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/AssignmentModulContactRepository.java
@@ -0,0 +1,45 @@
+/*
+ *******************************************************************************
+ * 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.TblAddress;
+import org.eclipse.openk.contactbasedata.model.TblAssignmentModulContact;
+import org.eclipse.openk.contactbasedata.model.TblContact;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+
+public interface AssignmentModulContactRepository extends JpaRepository<TblAssignmentModulContact, Long> {
+
+    public Optional<TblAssignmentModulContact> findByUuid(UUID uuid);
+
+    Optional<TblAssignmentModulContact> findByTblContactAndUuid(TblContact tblContact, UUID uuid);
+
+    @Query("select a from TblAssignmentModulContact a where a.tblContact.uuid = ?1")
+    public List< TblAssignmentModulContact > findByTblContactUuid(final UUID contactUuid);
+
+    @Query("select count(*) from TblAssignmentModulContact a where a.tblContact.id=:contactId and a.modulName=:modulName")
+    Long countByContactIdAndModuleName(@Param("contactId") Long contactId, @Param("modulName") String modulName);
+
+    @Query("select count(*) from TblAssignmentModulContact a where a.tblContact.id=:contactId and a.modulName= :modulName and a.uuid <> :assignmentUuid")
+    Long countByContactIdAndUuidAndModulNameIsNotSame(@Param("contactId") Long supplierId, @Param("assignmentUuid") UUID assignmentUuid , @Param("modulName") String modulName);
+
+}
+
+
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java
new file mode 100644
index 0000000..822ac61
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactService.java
@@ -0,0 +1,123 @@
+/*
+ *******************************************************************************
+ * 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.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.AssignmentModulContactMapper;
+import org.eclipse.openk.contactbasedata.model.TblAddress;
+import org.eclipse.openk.contactbasedata.model.TblAssignmentModulContact;
+import org.eclipse.openk.contactbasedata.model.TblContact;
+import org.eclipse.openk.contactbasedata.repository.AddressRepository;
+import org.eclipse.openk.contactbasedata.repository.AddressTypeRepository;
+import org.eclipse.openk.contactbasedata.repository.AssignmentModulContactRepository;
+import org.eclipse.openk.contactbasedata.repository.ContactRepository;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.AssignmentModulContactDto;
+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;
+
+@Log4j2
+@Service
+public class AssignmentModulContactService {
+    @Autowired
+    private AssignmentModulContactRepository assignmentModulContactRepository;
+
+    @Autowired
+    private ContactRepository contactRepository;
+
+    @Autowired
+    AssignmentModulContactMapper assignmentModulContactMapper;
+
+    public List<AssignmentModulContactDto> getAssignments(UUID contactUuid) {
+        List<TblAssignmentModulContact> tblAssignmentsList = assignmentModulContactRepository
+                .findByTblContactUuid(contactUuid);
+
+        return tblAssignmentsList.stream().map(assignmentModulContactMapper::toAssignmentModulContactDto).collect(Collectors.toList());
+    }
+
+    @Transactional
+    public AssignmentModulContactDto insertAssignment(UUID contactUuid, AssignmentModulContactDto assignmentDto) {
+
+        TblContact tblContact = contactRepository
+                                .findByUuid(contactUuid)
+                                .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+
+        TblAssignmentModulContact assignmentToSave = assignmentModulContactMapper.toTblAssignmentModulContact(assignmentDto);
+        assignmentToSave.setUuid(UUID.randomUUID());
+        assignmentToSave.setTblContact(tblContact);
+
+        if ( !checkUniqueAssignmentForContactAndModuleForInsert(tblContact.getId(), assignmentDto.getModulName())) {
+            throw new OperationDeniedException(OperationType.INSERT, "assignment.already.existing");
+        }
+
+        TblAssignmentModulContact savedAssignment = assignmentModulContactRepository.save(assignmentToSave);
+        return assignmentModulContactMapper.toAssignmentModulContactDto(savedAssignment);
+    }
+
+    @Transactional
+    public AssignmentModulContactDto updateAssignment(UUID contactUuid, AssignmentModulContactDto assignmentDto) {
+
+        TblContact contact = contactRepository.findByUuid(contactUuid)
+                .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+
+        TblAssignmentModulContact tblAssignment = assignmentModulContactRepository.findByUuid(assignmentDto.getUuid())
+                .orElseThrow(() -> new NotFoundException("assignment.uuid.not.existing"));
+
+        TblAssignmentModulContact assignmentToSave = assignmentModulContactMapper.toTblAssignmentModulContact(assignmentDto);
+        assignmentToSave.setTblContact(contact);
+        assignmentToSave.setId(tblAssignment.getId());
+
+        if ( !checkUniqueAssignmentForContactAndModuleForUpdate(contact.getId(), assignmentDto.getUuid(), assignmentDto.getModulName())) {
+            throw new OperationDeniedException(OperationType.UPDATE, "assignment.already.existing");
+        }
+
+        TblAssignmentModulContact savedAssignment = assignmentModulContactRepository.save(assignmentToSave);
+        return assignmentModulContactMapper.toAssignmentModulContactDto(savedAssignment);
+    }
+
+
+    @Transactional
+    public void deleteAssignment(UUID contactUuid, UUID assignmentUuid) {
+        TblContact tblContact = contactRepository.findByUuid(contactUuid)
+                .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+        TblAssignmentModulContact tblAssignment = assignmentModulContactRepository.findByTblContactAndUuid(tblContact, assignmentUuid)
+                .orElseThrow(() -> new NotFoundException("assignment.uuid.not.existing"));
+
+        assignmentModulContactRepository.delete(tblAssignment);
+    }
+
+    private boolean checkUniqueAssignmentForContactAndModuleForInsert(Long contactId, String modulName){
+        return assignmentModulContactRepository.countByContactIdAndModuleName(contactId, modulName) == 0;
+    }
+
+    private boolean checkUniqueAssignmentForContactAndModuleForUpdate( Long contactId, UUID assignmentUuid, String modulName){
+       Long result = assignmentModulContactRepository.countByContactIdAndUuidAndModulNameIsNotSame(contactId, assignmentUuid, modulName) ;
+       return result==0;
+    }
+
+
+
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/AssignmentModulContactDto.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/AssignmentModulContactDto.java
new file mode 100644
index 0000000..8c7d544
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/AssignmentModulContactDto.java
@@ -0,0 +1,38 @@
+/*
+ *******************************************************************************
+ * 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.viewmodel;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.UUID;
+
+@Data
+public class AssignmentModulContactDto implements Serializable {
+
+    @JsonProperty("id")
+    private UUID uuid;
+
+    @JsonProperty("contactId")
+    private UUID contactUuid;
+
+    private String modulName;
+    private Date assignmentDate;
+    private Date expiringDate;
+    private Date deletionLockUntil;
+    private String assignmentNote;
+
+}
diff --git a/src/main/resources/db/migration/V0_10__CREATE_CBD_DB.sql b/src/main/resources/db/migration/V0_10__CREATE_CBD_DB.sql
new file mode 100644
index 0000000..1c438ca
--- /dev/null
+++ b/src/main/resources/db/migration/V0_10__CREATE_CBD_DB.sql
@@ -0,0 +1,638 @@
+-----------------------------------------------------------------------------------
+-- *******************************************************************************
+-- * 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),
+  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 );
+
+
+-- ---------------------------------------------
+-- 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),
+   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);
+
+-- -------------------------------------
+-- 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,
+	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,
+	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.id
+	AND com.fk_communication_type=(
+		SELECT ct.id FROM ref_communication_type ct WHERE UPPER(ct.type) LIKE 'MAIL' LIMIT 1 ) ) ;
+
+
+
+
diff --git a/src/main/resources/db/migration/V0_9__CREATE_CBD_DB.sql b/src/main/resources/db/migration/V0_9__CREATE_CBD_DB.sql
index 3bc2c39..1c438ca 100644
--- a/src/main/resources/db/migration/V0_9__CREATE_CBD_DB.sql
+++ b/src/main/resources/db/migration/V0_9__CREATE_CBD_DB.sql
@@ -1,4 +1,4 @@
------------------------------------------------------------------------------------
+-----------------------------------------------------------------------------------
 -- *******************************************************************************
 -- * Copyright (c) 2019 Contributors to the Eclipse Foundation
 -- *
diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties
index 5396952..709e3ac 100644
--- a/src/main/resources/messages.properties
+++ b/src/main/resources/messages.properties
@@ -17,3 +17,4 @@
 company.contact.person.not.matching= Die \u00fcbergebenen UUIDs einer Firma und einer Kontaktperson passen nicht zueinander 
 company.contact.uuid.not.existing= Die \u00fcbergebene UUID einer Firma existiert nicht
 contact.person.uuid.not.existing= Die \u00fcbergebene UUID einer Kontaktperson existiert nicht
+assignment.uuid.not.existing= Die \u00fcbergebene UUID einer Zuweisung 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 fad5538..ed0fcf1 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/config/TestConfiguration.java
@@ -69,6 +69,9 @@
     CommunicationMapper communicationMapper() { return new CommunicationMapperImpl(); }
 
     @Bean
+    AssignmentModulContactMapper assignmentModulContactMapper() { return new AssignmentModulContactMapperImpl(); }
+
+    @Bean
     public VersionService myVersionService() {
         return new VersionService();
     }
@@ -108,4 +111,7 @@
 
     @Bean
     public BaseContactService myBaseContactService() { return new BaseContactService(); }
+
+    @Bean
+    public AssignmentModulContactService myAssignmentModulContactService() { return new AssignmentModulContactService(); }
 }
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/AssignmentModulContactControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/AssignmentModulContactControllerTest.java
new file mode 100644
index 0000000..e8e7776
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/AssignmentModulContactControllerTest.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.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.AssignmentModulContactService;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.AssignmentModulContactDto;
+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.context.ActiveProfiles;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.sql.Date;
+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
+@ActiveProfiles("test") // Todo: Find a better way to configure the tests
+public class AssignmentModulContactControllerTest {
+
+    @MockBean
+    private AssignmentModulContactService assignmentService;
+
+    @Autowired
+    private MockMvc mockMvc;
+
+    @Test
+    public void shouldReturnAssignmentsForAContact() throws Exception {
+        List<AssignmentModulContactDto> listDtos = MockDataHelper.mockAssignmentModulContactDtoList();
+
+        when(assignmentService.getAssignments(any(UUID.class))).thenReturn(listDtos);
+
+        mockMvc.perform(get("/contacts/{uuid}/assignments", UUID.randomUUID()))
+                .andExpect(status().is2xxSuccessful())
+                .andExpect(content().contentType(MediaType.APPLICATION_JSON));
+    }
+
+
+    @Test
+    public void shouldInsertAssignment() throws Exception {
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        assignmentDto.setUuid(UUID.fromString("394dce82-41af-11ea-b77f-2e728ce88125"));
+        assignmentDto.setContactUuid(UUID.fromString("5b164ab2-41af-11ea-b77f-2e728ce88125"));
+        assignmentDto.setAssignmentDate(Date.valueOf("2020-12-24"));
+        assignmentDto.setAssignmentNote("nur für Tests");
+        assignmentDto.setDeletionLockUntil(Date.valueOf("2021-12-24"));
+        assignmentDto.setExpiringDate(Date.valueOf("2022-12-24"));
+        assignmentDto.setModulName("Störinfos");
+
+        when(assignmentService.insertAssignment(any(UUID.class), any(AssignmentModulContactDto.class)))
+                .thenReturn(assignmentDto);
+
+        mockMvc.perform(post("/contacts/{uuid}/assignments", assignmentDto.getContactUuid())
+                .contentType(MediaType.APPLICATION_JSON)
+                .content(new ObjectMapper().writeValueAsString(assignmentDto)))
+                .andExpect(jsonPath("$.id", Matchers.is("394dce82-41af-11ea-b77f-2e728ce88125")))
+                .andExpect(jsonPath("$.contactId", Matchers.is("5b164ab2-41af-11ea-b77f-2e728ce88125" )))
+                .andExpect(jsonPath("$.assignmentDate", Matchers.is("2020-12-24" )))
+                .andExpect(jsonPath("$.assignmentNote", Matchers.is("nur für Tests" )))
+                .andExpect(jsonPath("$.deletionLockUntil", Matchers.is("2021-12-24" )))
+                .andExpect(jsonPath("$.expiringDate", Matchers.is("2022-12-24" )))
+                .andExpect(jsonPath("$.modulName", Matchers.is("Störinfos" )));
+
+    }
+
+
+    @Test
+    public void shouldUpdateAssignment() throws Exception {
+
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        when( assignmentService.updateAssignment(any(UUID.class), any(AssignmentModulContactDto.class))).thenReturn(assignmentDto);
+
+        mockMvc.perform(put("/contacts/{contactUuid}/assignments/{assignmentUuid}", assignmentDto.getContactUuid(), assignmentDto.getUuid())
+                .contentType(MediaType.APPLICATION_JSON)
+                .content(new ObjectMapper().writeValueAsString(assignmentDto)))
+                .andExpect(status().is2xxSuccessful());
+    }
+//
+    @Test
+    public void shouldNotUpdateAddress() throws Exception {
+
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        when( assignmentService.updateAssignment(any(UUID.class), any(AssignmentModulContactDto.class))).thenReturn(assignmentDto);
+
+        mockMvc.perform(put("/contacts/{contactUuid}/assignments/{assignmentUuid}", assignmentDto.getContactUuid(), UUID.randomUUID().toString())
+                .contentType(MediaType.APPLICATION_JSON)
+                .content(new ObjectMapper().writeValueAsString(assignmentDto)))
+                .andExpect(status().isBadRequest());
+    }
+
+    @Test
+    public void shouldDeleteAddress() throws Exception {
+        mockMvc.perform(delete("/contacts/{contactUuid}/assignments/{assignmentUuid}", UUID.randomUUID(), UUID.randomUUID())
+                .contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().is2xxSuccessful());
+    }
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactServiceTest.java
new file mode 100644
index 0000000..e9b6215
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/AssignmentModulContactServiceTest.java
@@ -0,0 +1,217 @@
+/*
+ *******************************************************************************
+ * 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.exceptions.NotFoundException;
+import org.eclipse.openk.contactbasedata.exceptions.OperationDeniedException;
+import org.eclipse.openk.contactbasedata.model.RefAddressType;
+import org.eclipse.openk.contactbasedata.model.TblAddress;
+import org.eclipse.openk.contactbasedata.model.TblAssignmentModulContact;
+import org.eclipse.openk.contactbasedata.model.TblContact;
+import org.eclipse.openk.contactbasedata.repository.AddressRepository;
+import org.eclipse.openk.contactbasedata.repository.AddressTypeRepository;
+import org.eclipse.openk.contactbasedata.repository.AssignmentModulContactRepository;
+import org.eclipse.openk.contactbasedata.repository.ContactRepository;
+import org.eclipse.openk.contactbasedata.support.MockDataHelper;
+import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.viewmodel.AssignmentModulContactDto;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.mockito.stubbing.Answer;
+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.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@DataJpaTest
+@ContextConfiguration(classes = {TestConfiguration.class})
+
+public class AssignmentModulContactServiceTest {
+    @Qualifier("myAssignmentModulContactService")
+    @Autowired
+    private AssignmentModulContactService assignmentService;
+
+    @MockBean
+    private AssignmentModulContactRepository assignmentRepository;
+
+    @MockBean
+    private ContactRepository contactRepository;
+
+
+    @Test
+    public void shouldReturnAssignmentsByContactUuid() {
+
+        List<TblAssignmentModulContact> listTblAssignments = MockDataHelper.mockTblAssignmentsList();
+        when(assignmentRepository.findByTblContactUuid( any(UUID.class)) ).thenReturn(listTblAssignments);
+
+        List<AssignmentModulContactDto> tblAssignmentsList = assignmentService.getAssignments(UUID.randomUUID());
+        assertEquals(tblAssignmentsList.size(), 2 );
+    }
+
+    @Test
+    public void shouldUpdateAssignment() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.of(tblContact));
+        when(assignmentRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblAssignment));
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+        when(assignmentRepository.countByContactIdAndUuidAndModulNameIsNotSame(anyLong(),any(UUID.class),anyString())).thenReturn(0L);
+
+        AssignmentModulContactDto savedAssignment = assignmentService.updateAssignment(assignmentDto.getUuid(), assignmentDto);
+
+        assertEquals(tblAssignment.getTblContact().getUuid(), savedAssignment.getContactUuid());
+        assertEquals(tblAssignment.getUuid(), savedAssignment.getUuid());
+        assertEquals(tblAssignment.getAssignmentDate(), savedAssignment.getAssignmentDate());
+        assertEquals(tblAssignment.getAssignmentNote(), savedAssignment.getAssignmentNote());
+        assertEquals(tblAssignment.getDeletionLockUntil(), savedAssignment.getDeletionLockUntil());
+        assertEquals(tblAssignment.getExpiringDate(), savedAssignment.getExpiringDate());
+        assertEquals(tblAssignment.getModulName(), savedAssignment.getModulName());
+    }
+
+    @Test
+    public void shouldNotUpdateAssignment_Exception1() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.empty());
+        when(assignmentRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblAssignment));
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+        when(assignmentRepository.countByContactIdAndUuidAndModulNameIsNotSame(anyLong(),any(UUID.class),anyString())).thenReturn(0L);
+
+        assertThrows( NotFoundException.class, () -> assignmentService.updateAssignment(assignmentDto.getUuid(), assignmentDto));
+    }
+
+    @Test
+    public void shouldNotUpdateAssignment_Exception2() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.of(tblContact));
+        when(assignmentRepository.findByUuid(any(UUID.class))).thenReturn(Optional.empty());
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+        when(assignmentRepository.countByContactIdAndUuidAndModulNameIsNotSame(anyLong(),any(UUID.class),anyString())).thenReturn(0L);
+
+        assertThrows( NotFoundException.class, () -> assignmentService.updateAssignment(assignmentDto.getUuid(), assignmentDto));
+    }
+
+    @Test
+    public void shouldNotUpdateAssignment_Exception3() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.of(tblContact));
+        when(assignmentRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblAssignment));
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+        when(assignmentRepository.countByContactIdAndUuidAndModulNameIsNotSame(anyLong(),any(UUID.class),anyString())).thenReturn(4L);
+
+        assertThrows( OperationDeniedException.class, () -> assignmentService.updateAssignment(assignmentDto.getUuid(), assignmentDto));
+
+    }
+
+    @Test
+    public void shouldInsertAssignment() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.of(tblContact));
+        when(assignmentRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblAssignment));
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+        when(assignmentRepository.countByContactIdAndModuleName(anyLong(), anyString())).thenReturn(0L);
+
+        AssignmentModulContactDto savedAssignment = assignmentService.insertAssignment(assignmentDto.getUuid(), assignmentDto);
+
+        assertNotNull(savedAssignment.getContactUuid());
+        assertEquals(tblAssignment.getTblContact().getUuid(), savedAssignment.getContactUuid());
+        assertEquals(tblAssignment.getAssignmentDate(), savedAssignment.getAssignmentDate());
+        assertEquals(tblAssignment.getAssignmentNote(), savedAssignment.getAssignmentNote());
+        assertEquals(tblAssignment.getDeletionLockUntil(), savedAssignment.getDeletionLockUntil());
+        assertEquals(tblAssignment.getExpiringDate(), savedAssignment.getExpiringDate());
+        assertEquals(tblAssignment.getModulName(), savedAssignment.getModulName());
+
+    }
+
+    @Test
+    public void shouldNotInsertAssignment_Exception_1() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.empty());
+        when(assignmentRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblAssignment));
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+        when(assignmentRepository.countByContactIdAndModuleName(anyLong(), anyString())).thenReturn(0L);
+
+        assertThrows( NotFoundException.class, () -> assignmentService.insertAssignment(assignmentDto.getUuid(), assignmentDto));
+
+    }
+
+
+    @Test
+    public void shouldNotInsertAssignment_Exception_2() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        AssignmentModulContactDto assignmentDto = MockDataHelper.mockAssignmentModulContactDto();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.of(tblContact));
+        when(assignmentRepository.countByContactIdAndModuleName(anyLong(), anyString())).thenReturn(2L);
+        when(assignmentRepository.save(any(TblAssignmentModulContact.class))).thenReturn(tblAssignment);
+
+        assertThrows( OperationDeniedException.class, () -> assignmentService.insertAssignment(assignmentDto.getUuid(), assignmentDto));
+
+    }
+
+
+    @Test
+    public void shouldDeleteAssignment() {
+        TblAssignmentModulContact tblAssignment = MockDataHelper.mockTblAssignmentModulContact();
+        TblContact tblContact = MockDataHelper.mockTblContact();
+        tblAssignment.setTblContact(tblContact);
+
+        when (contactRepository.findByUuid( any(UUID.class))).thenReturn(Optional.of(tblContact));
+        when(assignmentRepository.findByTblContactAndUuid(any(TblContact.class), any(UUID.class))).thenReturn(Optional.of(tblAssignment));
+        Mockito.doNothing().when(assignmentRepository).delete( isA( TblAssignmentModulContact.class ));
+
+        assignmentService.deleteAssignment(tblContact.getUuid(), tblAssignment.getUuid());
+
+        Mockito.verify(assignmentRepository, times(1)).delete( tblAssignment );
+    }
+
+}
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 e6b52cd..ce82677 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
@@ -20,6 +20,7 @@
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
+import java.sql.Date;
 
 import java.util.*;
 
@@ -620,4 +621,87 @@
         return list;
     }
 
+    public static AssignmentModulContactDto mockAssignmentModulContactDto(){
+
+        AssignmentModulContactDto assignmentDto = new AssignmentModulContactDto();
+
+        assignmentDto.setUuid(UUID.randomUUID());
+        assignmentDto.setContactUuid(UUID.randomUUID());
+        assignmentDto.setAssignmentDate(Date.valueOf("2022-12-24"));
+        assignmentDto.setAssignmentNote("nur für Tests");
+        assignmentDto.setDeletionLockUntil(Date.valueOf("2022-12-24"));
+        assignmentDto.setExpiringDate(Date.valueOf("2022-12-24"));
+        assignmentDto.setModulName("Geplante Netzmassnahme");
+
+        return assignmentDto;
+    }
+
+
+    public static List<AssignmentModulContactDto> mockAssignmentModulContactDtoList(){
+
+        List<AssignmentModulContactDto> list = new ArrayList<>();
+
+        AssignmentModulContactDto assignmentDto1 = mockAssignmentModulContactDto();
+
+        AssignmentModulContactDto assignmentDto2 = new AssignmentModulContactDto();
+        assignmentDto2.setUuid(UUID.randomUUID());
+        assignmentDto2.setContactUuid(UUID.randomUUID());
+        assignmentDto2.setAssignmentDate(Date.valueOf("2022-01-24"));
+        assignmentDto2.setAssignmentNote("Testuser");
+        assignmentDto2.setDeletionLockUntil(Date.valueOf("2022-01-24"));
+        assignmentDto2.setExpiringDate(Date.valueOf("2022-01-24"));
+        assignmentDto2.setModulName("Ferienkalender");
+
+        AssignmentModulContactDto assignmentDto3 = new AssignmentModulContactDto();
+        assignmentDto3.setUuid(UUID.randomUUID());
+        assignmentDto3.setContactUuid(UUID.randomUUID());
+        assignmentDto3.setAssignmentDate(Date.valueOf("2022-04-24"));
+        assignmentDto3.setAssignmentNote("Testkoch");
+        assignmentDto3.setDeletionLockUntil(Date.valueOf("2022-04-24"));
+        assignmentDto3.setExpiringDate(Date.valueOf("2022-04-24"));
+        assignmentDto3.setModulName("Kochdienste");
+
+        list.add(assignmentDto1);
+        list.add(assignmentDto2);
+        list.add(assignmentDto3);
+
+        return list;
+    }
+
+    public static TblAssignmentModulContact mockTblAssignmentModulContact(){
+
+        TblAssignmentModulContact tblAssignment = new TblAssignmentModulContact();
+
+        tblAssignment.setUuid(UUID.randomUUID());
+        tblAssignment.setTblContact(mockTblContact());
+        tblAssignment.setAssignmentDate(Date.valueOf("2022-12-01"));
+        tblAssignment.setAssignmentNote("nur für Tests");
+        tblAssignment.setDeletionLockUntil(Date.valueOf("2023-12-01"));
+        tblAssignment.setExpiringDate(Date.valueOf("2024-12-01"));
+        tblAssignment.setModulName("Reparaturdienste");
+
+        return tblAssignment;
+    }
+
+    public static List<TblAssignmentModulContact> mockTblAssignmentsList(){
+        List<TblAssignmentModulContact> list = new ArrayList<>();
+
+        TblAssignmentModulContact tblAssignment  = mockTblAssignmentModulContact();
+
+        TblAssignmentModulContact tblAssignment2 = new TblAssignmentModulContact();
+        tblAssignment2.setUuid(UUID.randomUUID());
+        tblAssignment2.setTblContact(mockTblContact());
+        tblAssignment2.setAssignmentDate(Date.valueOf("2020-12-01"));
+        tblAssignment2.setAssignmentNote("nur für Tests");
+        tblAssignment2.setDeletionLockUntil(Date.valueOf("2025-12-01"));
+        tblAssignment2.setExpiringDate(Date.valueOf("2030-12-01"));
+        tblAssignment2.setModulName("Störungsstatistik");
+
+        list.add(tblAssignment);
+        list.add(tblAssignment2);
+
+
+        return list;
+    }
+
 }