Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.contactBaseData.backend into KON_14-Kontakte-Modulzuordnung
diff --git a/pom.xml b/pom.xml
index 4a33097..f9cdd8d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,7 @@
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<springfox.version>2.9.2</springfox.version>
+ <spring-security-test.version>5.2.1.RELEASE</spring-security-test.version>
<powerMockReflect.version>2.0.0</powerMockReflect.version>
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
<asciidoctor-maven-plugin-version>1.5.3</asciidoctor-maven-plugin-version>
@@ -145,6 +146,7 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
+ <version>${spring-security-test.version}</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/src/main/asciidoc/architectureDocumentation/architectureDocumentation.adoc b/src/main/asciidoc/architectureDocumentation/architectureDocumentation.adoc
index 12b1231..313b619 100644
--- a/src/main/asciidoc/architectureDocumentation/architectureDocumentation.adoc
+++ b/src/main/asciidoc/architectureDocumentation/architectureDocumentation.adoc
@@ -105,8 +105,6 @@
=== Technical Constraints
-TODO: Bibliotheken und Versionen aktualisieren
-
The following technical constraints are given:
.Technical Contraints
@@ -136,7 +134,7 @@
|Programming language
a|* Backend: Java 1.8
-* Frontend: Angular 4.0.0 (Javascript, Typescript, HTML5, CSS3)
+* Frontend: Angular 7+ (Javascript, Typescript, HTML5, CSS3)
|IDE
a|* Not restricted (Eclipse, IntelliJ, Microsoft Developer Studio, Microsoft Visual Code ...)
@@ -178,11 +176,283 @@
|org.springframework.boot.spring-boot-starter-parent|2.2.1.RELEASE
a|
-[source,xml]
-----
-
-----
||Apache License 2.0|Backend
+
+|org.springframework.boot.spring-boot-starter-data-jpa|2.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.boot.spring-boot-starter-oauth2-client|2.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.boot.spring-boot-starter-security|2.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.boot.spring-boot-starter-web|2.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.flywaydb.flyway-core|6.0.8
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.cloud.spring-cloud-starter-openfeign|2.2.0.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.cloud.spring-cloud-starter-netflix-ribbon|2.2.0.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.keycloak.keycloak-core|3.4.2_Final
+a|
+||Apache License 2.0|Backend
+
+|org.postgresql.postgresql|42.2.8
+a|
+||New BSD License|Backend
+
+|org.projectlombok.lombok|1.18.10
+a|
+||MIT|Backend
+
+|org.mapstruct.mapstruct-processor|1.2.0.Final
+a|
+||Apache License 2.0|Backend
+
+|io.jsonwebtoken.jjwt|0.9.1
+a|
+||Apache License 2.0|Backend
+
+|io.springfox.springfox-swagger2|2.9.2
+a|
+||Apache License 2.0|Backend
+
+|io.springfox.springfox-swagger-ui|2.9.2
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.boot.spring-boot-starter-test|2.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.security.spring-security-test|5.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.powermock.powermock-reflect|2.0.0
+a|
+||Apache License 2.0|Backend
+
+|com.h2database.h2|1.4.200
+a|
+||EPL|Backend
+
+|org.springframework.cloud.spring-cloud-dependencies|Hoxton.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.springframework.boot.spring-boot-maven-plugin|2.2.1.RELEASE
+a|
+||Apache License 2.0|Backend
+
+|org.jacoco.jacoco-maven-plugin|0.7.9
+a|
+||EPL 2.0|Backend
+
+|org.sonarsource.scanner.maven.sonar-maven-plugin|3.2
+a|
+||LGPL 3.0|Backend
+
+|org.asciidoctor.asciidoctor-maven-plugin|1.5.3
+a|
+||Apache License 2.0|Backend
+
+
+|org.jruby.jruby-complete|9.0.0.0
+a|
+||EPL 2.0|Backend
+
+|org.asciidoctor.asciidoctorj-pdf|1.5.0-alpha.11
+a|
+||Apache 2.0|Backend
+
+
+|org.asciidoctor.asciidoctorj|1.5.4
+a|
+||Apache 2.0|Backend
+
+
+|org.asciidoctor.asciidoctorj-pdf|1.5.0-alpha.11
+a|
+||Apache 2.0|Backend
+
+
+|org.asciidoctor.asciidoctorj-diagram|1.5.4.1
+a|
+||Apache 2.0|Backend
+
+
+|Angular Font Awesome|3.1.2
+a|
+||MIT License|Frontend
+
+
+|@auth0/angular-jwt|3.0.1
+a|
+||MIT License|Frontend
+
+
+|font-awesome|4.7.0
+a|
+||MIT License|Frontend
+
+
+|@ngrx/core|1.2.0
+a|
+||MIT License|Frontend
+
+
+|@ngrx/effects|8-2-0
+a|
+||MIT License|Frontend
+
+
+|@ngrx/store|8.3.0
+a|
+||MIT License|Frontend
+
+
+|@ngrx/store-devtools|8.2.0
+a|
+||MIT License|Frontend
+
+
+|@ngx-translate/core|11.0.1
+a|
+||MIT License|Frontend
+
+
+|@ngx-translate/http-loader|4.0.0
+a|
+||MIT License|Frontend
+
+
+|ag-grid-angular|21.2.1
+a|
+||MIT License|Frontend
+
+
+|ag-grid-community|21.2.1
+a|
+||MIT License|Frontend
+
+
+|angular2-notifications|2.0.0
+a|
+||MIT License|Frontend
+
+
+|bootstrap|4.4.1
+a|
+||MIT License|Frontend
+
+
+|jquery|3.4.1
+a|
+||MIT License|Frontend
+
+
+|classlist.js|1.1.20150312
+a|
+||MIT License|Frontend
+
+
+|core-js|3.2.1
+a|
+||MIT License|Frontend
+
+
+|moment|2.24.0
+a|
+||MIT License|Frontend
+
+
+|ng2-popover|0.0.14
+a|
+||MIT License|Frontend
+
+
+|ngrx-forms|5.2.1
+a|
+||MIT License|Frontend
+
+
+|npm-install-peers|1.2.1
+a|
+||MIT License|Frontend
+
+
+|reselect|4.0.0
+a|
+||MIT License|Frontend
+
+
+|rxjs|6.5.3
+a|
+||MIT License|Frontend
+
+
+|rxjs-compat|6.5.4
+a|
+||MIT License|Frontend
+
+
+|ts-helpers|1.1.2
+a|
+||MIT License|Frontend
+
+
+|tslib|1.10.0
+a|
+||MIT License|Frontend
+
+
+|web-animations-js|2.3.2
+a|
+||MIT License|Frontend
+
+
+|zone.js|0.10.1
+a|
+||MIT License|Frontend
+
+
+|@swimlane/ngx-datatable|15.0.2
+a|
+||MIT License|Frontend
+
+
+|puppeteer|2.0.0
+a|
+||MIT License|Frontend
+
+
+|ngx-toastr|11.2.1
+a|
+||MIT License|Frontend
+
+|popper.js|1.16.0
+a|
+||MIT License|Frontend
+
+|@ng-bootstrap|5.1.5
+a|
+||MIT License|Frontend
+
+
|=========================================================
== System Scope and Context
@@ -258,7 +528,7 @@
This component implements the business functionality of the contact base data. And it provides services, that the
contactBaseDataFE can use the functions in the frontend.
-The "spring boot/sprint cloud" framework is used to implement this application.
+The "spring boot/spring cloud" framework is used to implement this application.
==== ContactBaseDataDev-DB (Database tier)
@@ -304,12 +574,12 @@
node "Contact Base Data Backend (simplified)" {
component RestService
- component ViewModel_API
+ component ViewModel_API__DTO
}
Services .. RestService
-Model .. ViewModel_API
-RestService --> ViewModel_API
+Model .. ViewModel_API__DTO
+RestService --> ViewModel_API__DTO
----
@@ -319,11 +589,12 @@
. *Presentation layer* - Represented by
.. REST-Srv
-.. View model
+.. View model/DTO
. *Controller layer* - Represented by
.. Controller
+.. Service
. *Model layer* - Represented by
-.. DAO
+.. Repository
.. Model
@@ -339,23 +610,26 @@
component RestService
- component ViewModel_API
+ component ViewModel_DTO
component Controller
- component DAO
+ component Service
- RestService --> ViewModel_API
+ component Repository
+
+ RestService --> ViewModel_DTO
RestService --> Controller
- DAO --> Model
- Controller --> DAO
- }
+ Controller --> Service
+ Service --> Repository
+ Repository --> Model
+ }
node DBMS {
component ContactBaseDataDB
}
-DAO --> ContactBaseDataDB
+Repository --> ContactBaseDataDB
----
==== ContactBaseData-DB (database tier)
@@ -440,18 +714,35 @@
===== Configuration of the contact base data backend
-When starting the microservice of the contact base data backend you have to provide a configuration "YML"
-file.
-TODO: Describe configuration possibilities.
+The backend service is configured in the * .yaml files, which are located in the JAR file.
+This yml-file can be divided into different configuration profiles.
+When starting the backend-service one has the possibility to specify
+the active profile
+
+* *spring.datasource* configuration section for the database connection
+* *flyway.enabled* If enabled=true then the database migrations
+ will automatically performed when starting the application
+ (this parameter should normally be set to "false"
+* *server.max-http-header-size* Maximum size for the http-headers
+* *jwt.tokenHeader* Name of the http-header which carries the authentication-token.
+ (should be "Authorization")
+* *jwt.useStaticJwt* If set to "true" then the backend will use *jwt.staticJwt*
+ as Authorization-token. (This won't work for calls to other modules
+ like the Auth'n'Auth-Modul, because the token will be out of date)
+* *authNAuthService.ribbon.listOfServers* Here one can configure the base
+ url to the Auth'n'Auth-Service
=== CI- and CD-Components
==== GIT-Repository
+Backend:
+https://git.eclipse.org/c/openk-usermodules/org.eclipse.openk-usermodules.contactBaseData.backend.git/
-TODO: Links to Repos
+Frontend:
+https://git.eclipse.org/c/openk-usermodules/org.eclipse.openk-usermodules.contactBaseData.frontend.git/
=== Continuous deployment
@@ -496,6 +787,7 @@
|AC|Architecture Committee|Architektur-Komittee|Gives framework and constraints according to architecture for oK projects.
|CNCU|Central Network Control Unit||
|DAO|Data Access Objects||
+|DTO|Data Transfer Object||
|DSO|Distribution System Operator|Verteilnetz-betreiber (VNB)|Manages the distribution network for energy, gas or water.
|EPL|Eclipse Public License||Underlying license model for Eclipse projects like contact-base-data@openK
|ESB|Enterprise Service Bus||Central instance to exchange data to overcome point-to-point connections.
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java b/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java
index 3dbfb09..65ba925 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/api/AuthNAuthApi.java
@@ -1,12 +1,32 @@
+/*
+ *******************************************************************************
+ * 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.api;
+import org.eclipse.openk.contactbasedata.viewmodel.UserModule;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
+import java.util.List;
+
@FeignClient(name = "${services.authNAuth.name}")
public interface AuthNAuthApi {
@GetMapping(value= "/portal/rest/beservice/checkAuth")
feign.Response isTokenValid(@RequestHeader("Authorization") String token );
+
+ @GetMapping(value= "/portal/rest/beservice/userModulesForUser")
+ List<UserModule> getUserModulesForUser(@RequestHeader("Authorization") String token );
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java b/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java
index 766d6d8..23b1a26 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/config/auth/JwtAuthenticationTokenFilter.java
@@ -76,8 +76,8 @@
token.getRealmAccess().getRoles().stream()
.forEach( x -> authorities.add(new SimpleGrantedAuthority("ROLE_"+x.toUpperCase())));
- UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(token.getName(), null,
- authorities);
+ UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(token.getName(), null, authorities);
+ auth.setDetails(bearerTkn);
context.setAuthentication(auth);
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java
index 3641442..faf8b5a 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/ContactController.java
@@ -49,11 +49,18 @@
@RequestParam( "contactType") Optional<String> contactType,
@RequestParam( "personTypeId" ) Optional<UUID> personTypeUuid,
@RequestParam( "searchText" ) Optional<String> searchText,
+ @RequestParam( "moduleName") Optional<String> moduleName,
+ @RequestParam( "withoutAssignedModule") Optional<Boolean> withoutAssignedModule,
+ @RequestParam( "expiringDataInPast" ) Optional<Boolean> expiringDataInPast,
@PageableDefault( sort = {"name"}, size = 20, direction = ASC) Pageable pageable ) {
return contactService.findDetailedContacts(
contactType.orElse(null),
personTypeUuid.orElse(null),
- searchText.orElse( null), pageable);
+ searchText.orElse( null),
+ moduleName.orElse(null),
+ withoutAssignedModule.orElse(Boolean.FALSE),
+ expiringDataInPast.orElse(Boolean.FALSE),
+ pageable);
}
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/UserModuleController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/UserModuleController.java
new file mode 100644
index 0000000..eced874
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/UserModuleController.java
@@ -0,0 +1,48 @@
+/*
+ *******************************************************************************
+ * 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.UserModuleService;
+import org.eclipse.openk.contactbasedata.viewmodel.UserModule;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@Log4j2
+@RestController
+@RequestMapping("/user-modules")
+public class UserModuleController {
+
+ @Autowired
+ private UserModuleService userModuleService;
+
+ @ApiOperation(value = "Ermitteln der UserModules vom Auth'n'Auth-Service")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
+ @GetMapping
+ public List<UserModule> getUserModules() {
+ return userModuleService.getUserModules();
+ }
+
+
+
+
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java b/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java
index 850468f..472dfdd 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/TblAssignmentModulContact.java
@@ -40,6 +40,4 @@
@JoinColumn( name = "fk_contact_id")
private TblContact tblContact;
-
-
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java b/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java
index f3ef0ec..f5cd6fe 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/TblContact.java
@@ -40,6 +40,9 @@
@OneToMany(cascade=CascadeType.ALL, mappedBy="tblContact", orphanRemoval = true)
private List<TblCommunication> communications = new ArrayList<>();
+ @OneToMany(cascade=CascadeType.ALL, mappedBy="tblContact", orphanRemoval = true)
+ private List<TblAssignmentModulContact> assignments = new ArrayList<>();
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java b/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java
index 7dc279e..e514d96 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/model/VwDetailedContact.java
@@ -17,8 +17,12 @@
import lombok.Data;
import org.springframework.data.annotation.Immutable;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
@Data
@@ -47,4 +51,5 @@
private String community;
private String email;
private String searchfield;
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
index bacbe7f..f63d8c1 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
@@ -15,11 +15,21 @@
package org.eclipse.openk.contactbasedata.repository;
import org.eclipse.openk.contactbasedata.model.TblContact;
+import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
import java.util.Optional;
import java.util.UUID;
public interface ContactRepository extends JpaRepository<TblContact, Long > {
public Optional<TblContact> findByUuid( UUID uuid );
+ @Query( "select c from TblContact c join c.assignments a where"
+ + "(COALESCE(:modulName) is null or COALESCE(:modulName) is not null AND a.modulName =:modulName)")
+ Page<TblContact> findByModulName(@Param("modulName")String modulName, Pageable pageable);
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java
index 821d897..e679c4f 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/DetailedContactRepository.java
@@ -21,18 +21,30 @@
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
+import java.util.Date;
import java.util.UUID;
public interface DetailedContactRepository extends PagingAndSortingRepository<VwDetailedContact, Long> {
Page<VwDetailedContact> findAll(Pageable pageable);
-
- @Query( "select dc from VwDetailedContact dc where"
- + "(COALESCE(:contactType) is null or COALESCE(:contactType) is not null AND dc.contactType=:contactType)"
+ @Query( "select dc from VwDetailedContact dc "
+ + " where (COALESCE(:contactType) is null or COALESCE(:contactType) is not null AND dc.contactType=:contactType)"
+ " and (COALESCE(:personType) is null or COALESCE(:personType) is not null AND dc.personTypeUuid=:personType)"
- + " and (COALESCE(:searchText) is null or COALESCE(:searchText) is not null AND dc.searchfield like %:searchText%)")
+ + " and (COALESCE(:searchText) is null or COALESCE(:searchText) is not null AND dc.searchfield like %:searchText%)"
+ + " and (COALESCE(:moduleName) is null or COALESCE(:moduleName) is not null AND dc.fkContactId in (select distinct amc.tblContact.id from TblAssignmentModulContact amc where amc.modulName=:moduleName))"
+ + " and (COALESCE(:withoutModule) = false or COALESCE(:withoutModule) = true AND dc.fkContactId not in "
+ + " (select distinct amc.tblContact.id from TblAssignmentModulContact amc)) "
+ + " and (COALESCE(:dateTimeNow) is null or COALESCE(:dateTimeNow) is not null AND dc.fkContactId in "
+ + " (select distinct amc.tblContact.id from TblAssignmentModulContact amc where "
+ + " amc.expiringDate is not null and amc.expiringDate < :dateTimeNow and "
+ + " (amc.deletionLockUntil is null or amc.deletionLockUntil is not null and amc.deletionLockUntil < :dateTimeNow )))"
+ )
Page<VwDetailedContact> findByFilter(@Param("contactType")String contactType,
@Param("personType") UUID personType,
@Param("searchText") String searchText,
+ @Param("moduleName") String moduleName,
+ @Param("withoutModule") boolean withoutModule,
+ @Param("dateTimeNow") Date dateTimeNow,
Pageable pageable);
}
+
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java
index bb17aaf..9957faf 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/CompanyService.java
@@ -131,6 +131,7 @@
private void mapEmail( ContactPersonDto dto, Map<UUID, TblContactPerson> cpMap ) {
+ // TODO: Move to Mapper
TblCommunication tblComm = cpMap.get(dto.getContactUuid()).getContact()
.getCommunications().stream()
.filter(comm -> comm.getRefCommunicationType().getId() == 1L)
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java
index f1b2521..e2bef26 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactPersonService.java
@@ -19,6 +19,7 @@
import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
import org.eclipse.openk.contactbasedata.mapper.ContactMapper;
import org.eclipse.openk.contactbasedata.mapper.ContactPersonMapper;
+import org.eclipse.openk.contactbasedata.model.TblCommunication;
import org.eclipse.openk.contactbasedata.model.TblContact;
import org.eclipse.openk.contactbasedata.model.TblContactPerson;
import org.eclipse.openk.contactbasedata.repository.*;
@@ -58,8 +59,8 @@
public ContactPersonDto findContactPerson(UUID contactPersonUuid) {
TblContactPerson tblContactPerson = contactPersonRepository
.findByTblContactUuid(contactPersonUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
- return contactPersonMapper.toContactPersonDto(tblContactPerson);
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
+ return setFromTblContactPerson(contactPersonMapper.toContactPersonDto(tblContactPerson), tblContactPerson);
}
@Transactional
@@ -75,7 +76,9 @@
setFromContactPersonDto( contactPersonToSave, contactPersonDto );
// Then save dependent Model-Object
- return contactPersonMapper.toContactPersonDto(contactPersonRepository.save(contactPersonToSave));
+ return setFromTblContactPerson(
+ contactPersonMapper.toContactPersonDto(contactPersonRepository.save(contactPersonToSave)),
+ contactPersonToSave);
}
@Transactional
@@ -84,7 +87,7 @@
TblContactPerson existingContactPerson = contactPersonRepository
.findByTblContactUuid(contactPersonDto.getContactUuid())
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
existingContactPerson.setLastName(contactPersonDto.getLastName());
existingContactPerson.setFirstName(contactPersonDto.getFirstName());
@@ -93,13 +96,14 @@
setFromContactPersonDto( existingContactPerson, contactPersonDto );
contactPersonUpdated = contactPersonRepository.save(existingContactPerson);
- return contactPersonMapper.toContactPersonDto(contactPersonUpdated);
+ ContactPersonDto retDto = contactPersonMapper.toContactPersonDto(contactPersonUpdated);
+ return setFromTblContactPerson(retDto, contactPersonUpdated);
}
@Transactional
public void deleteContactPerson(UUID contactUuid) {
TblContact tblContact = contactRepository.findByUuid(contactUuid)
- .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+ .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
TblContactPerson tblContactPerson = contactPersonRepository.findByTblContactUuid(contactUuid)
.orElseThrow(() -> new NotFoundException("contact.person.uuid.not.existing"));
@@ -107,6 +111,18 @@
contactRepository.delete(tblContact);
}
+ private ContactPersonDto setFromTblContactPerson( ContactPersonDto destDto, TblContactPerson srcTblContactPerson ) {
+ TblCommunication tblComm = srcTblContactPerson.getContact()
+ .getCommunications().stream()
+ .filter(comm -> comm.getRefCommunicationType().getId() == 1L)
+ .findFirst().orElse(null);
+// TODO: exchange constant 1L with DB-Solution
+ // TODO: Move to Mapper
+ destDto.setEmail(tblComm != null ? tblComm.getCommunicationData() : null );
+
+ return destDto;
+ }
+
private void setFromContactPersonDto( TblContactPerson destTblContactPerson, ContactPersonDto sourceDto ) {
if( sourceDto.getSalutationUuid() != null ) {
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java
index 4ade8d3..4dbe779 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/ContactService.java
@@ -15,13 +15,17 @@
package org.eclipse.openk.contactbasedata.service;
import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.mapper.ContactMapper;
import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
+import org.eclipse.openk.contactbasedata.repository.ContactRepository;
import org.eclipse.openk.contactbasedata.repository.DetailedContactRepository;
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 java.time.Instant;
+import java.util.Date;
import java.util.UUID;
@Log4j2
@@ -29,20 +33,36 @@
public class ContactService {
@Autowired
private DetailedContactRepository detailedContactRepository;
+ @Autowired
+ private ContactRepository contactRepository;
+ @Autowired
+ private ContactMapper contactMapper;
public Page<VwDetailedContact> findDetailedContacts(String contactType,
UUID personTypeUuid,
- String searchText, Pageable pageable) {
+ String searchText,
+ String moduleName,
+ boolean withoutModule,
+ boolean expiringDataInPast,
+ Pageable pageable) {
- if( contactType == null && personTypeUuid == null && searchText == null) {
+ if( contactType == null &&
+ personTypeUuid == null &&
+ searchText == null &&
+ moduleName == null &&
+ !withoutModule &&
+ !expiringDataInPast ) {
return detailedContactRepository.findAll(pageable);
}
else {
return detailedContactRepository.findByFilter( contactType,
personTypeUuid,
searchText != null ? searchText.toUpperCase() : null,
+ moduleName,
+ withoutModule,
+ expiringDataInPast ? Date.from(Instant.now()) : null,
pageable);
}
-
}
+
}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/UserModuleService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/UserModuleService.java
new file mode 100644
index 0000000..b0c9dc4
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/UserModuleService.java
@@ -0,0 +1,34 @@
+/*
+ *******************************************************************************
+ * 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.api.AuthNAuthApi;
+import org.eclipse.openk.contactbasedata.viewmodel.UserModule;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class UserModuleService {
+ @Autowired
+ private AuthNAuthApi authNAuthApi;
+
+ public List<UserModule> getUserModules() {
+ String bearerToken = (String)SecurityContextHolder.getContext().getAuthentication().getDetails();
+ return authNAuthApi.getUserModulesForUser(bearerToken);
+ }
+}
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/UserModule.java b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/UserModule.java
new file mode 100644
index 0000000..7f8fd82
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/contactbasedata/viewmodel/UserModule.java
@@ -0,0 +1,23 @@
+/*
+ *******************************************************************************
+ * 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 lombok.Data;
+
+@Data
+public class UserModule {
+ private String name;
+ private String color;
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 5ba8fd2..b1a50e9 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -73,7 +73,7 @@
jwt:
tokenHeader: Authorization
- useStaticJwt: true
+ useStaticJwt: false
staticJwt: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJIYlI3Z2pobmE2eXJRZnZJTWhUSV9tY2g3ZmtTQWVFX3hLTjBhZVl0bjdjIn0.eyJqdGkiOiI5MGI0NGFkOC1iYjlmLTQ1MzktYTQwYy0yYjQyZTNkNjNiOGEiLCJleHAiOjE1Nzg2NTU3OTUsIm5iZiI6MCwiaWF0IjoxNTc4NjU1NDk1LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvRWxvZ2Jvb2siLCJhdWQiOiJlbG9nYm9vay1iYWNrZW5kIiwic3ViIjoiODYyNjY5NmYtZjFhMi00ZGI1LTkyZWYtZTlhMjQ2Njg1YTU0IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZWxvZ2Jvb2stYmFja2VuZCIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjJmMWIzODE5LWZjNjQtNDEzNC1iNWQxLWY3ZWY4NzU5NDBkNCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiKiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsia29uLWFkbWluIiwia29uLXdyaXRlciIsImtvbi1hY2Nlc3MiLCJrb24tcmVhZGVyIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnt9LCJuYW1lIjoiVGVzdGVyRmlyc3RuYW1lX3J3YSBUZXN0ZXJMYXN0bmFtZV9yd2EiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ0ZXN0dXNlcl9yd2EiLCJnaXZlbl9uYW1lIjoiVGVzdGVyRmlyc3RuYW1lX3J3YSIsImZhbWlseV9uYW1lIjoiVGVzdGVyTGFzdG5hbWVfcndhIn0.DAYXuv4tKn8RXqO1jyttnD-tF4nShUBQyfe4bKbAiPAyY2x5YbAf3M4eXnLrGqo8-loGKldICC28bL0LaMA3KKkQEOfW5sfpGqoN6212vs89mOklt0TJYc5PMXwFgJ5WC_TKjdwq7-aaDafOEWehV0U1ut3s-94ovNYIEn29nzXm2W1ldoXJEq03F880jlysQ5zlRvGF7eXEEpFfI2URyyNQ2UWh0Ssfq-gOAt2pbF1u6prA5RfvUmZ3v1eu21YLGZtgqPqxb1l6odyH3ip15j_HdgnTeo52ymxuRUj65Mskme3V5ev2DitHI9vZgnpV8Idhb4TTWliBeGCOMfDFCg
server:
@@ -83,6 +83,24 @@
allowedOrigins: http://localhost:8080
corsEnabled: true
+
+---
+
+spring:
+ profiles: devserver-unsecure
+
+jwt:
+ tokenHeader: Authorization
+ useStaticJwt: true
+ staticJwt: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJIYlI3Z2pobmE2eXJRZnZJTWhUSV9tY2g3ZmtTQWVFX3hLTjBhZVl0bjdjIn0.eyJqdGkiOiI5MGI0NGFkOC1iYjlmLTQ1MzktYTQwYy0yYjQyZTNkNjNiOGEiLCJleHAiOjE1Nzg2NTU3OTUsIm5iZiI6MCwiaWF0IjoxNTc4NjU1NDk1LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvRWxvZ2Jvb2siLCJhdWQiOiJlbG9nYm9vay1iYWNrZW5kIiwic3ViIjoiODYyNjY5NmYtZjFhMi00ZGI1LTkyZWYtZTlhMjQ2Njg1YTU0IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZWxvZ2Jvb2stYmFja2VuZCIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjJmMWIzODE5LWZjNjQtNDEzNC1iNWQxLWY3ZWY4NzU5NDBkNCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiKiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsia29uLWFkbWluIiwia29uLXdyaXRlciIsImtvbi1hY2Nlc3MiLCJrb24tcmVhZGVyIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnt9LCJuYW1lIjoiVGVzdGVyRmlyc3RuYW1lX3J3YSBUZXN0ZXJMYXN0bmFtZV9yd2EiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ0ZXN0dXNlcl9yd2EiLCJnaXZlbl9uYW1lIjoiVGVzdGVyRmlyc3RuYW1lX3J3YSIsImZhbWlseV9uYW1lIjoiVGVzdGVyTGFzdG5hbWVfcndhIn0.DAYXuv4tKn8RXqO1jyttnD-tF4nShUBQyfe4bKbAiPAyY2x5YbAf3M4eXnLrGqo8-loGKldICC28bL0LaMA3KKkQEOfW5sfpGqoN6212vs89mOklt0TJYc5PMXwFgJ5WC_TKjdwq7-aaDafOEWehV0U1ut3s-94ovNYIEn29nzXm2W1ldoXJEq03F880jlysQ5zlRvGF7eXEEpFfI2URyyNQ2UWh0Ssfq-gOAt2pbF1u6prA5RfvUmZ3v1eu21YLGZtgqPqxb1l6odyH3ip15j_HdgnTeo52ymxuRUj65Mskme3V5ev2DitHI9vZgnpV8Idhb4TTWliBeGCOMfDFCg
+
+server:
+ port: 9156
+
+cors:
+ allowedOrigins: http://localhost:8080
+ corsEnabled: true
+
---
spring:
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java b/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java
index 1b79c1d..841fe76 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/controller/ContactControllerTest.java
@@ -30,8 +30,7 @@
import org.springframework.test.web.servlet.MockMvc;
import static org.hamcrest.Matchers.is;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -55,7 +54,7 @@
Page<VwDetailedContact> retPage = MockDataHelper.mockVDetailedContactPage();
when(contactService.findDetailedContacts(
- isNull(), isNull(), isNull(), any(Pageable.class))).thenReturn(retPage);
+ isNull(), isNull(), isNull(), isNull(), anyBoolean(), anyBoolean(), any(Pageable.class))).thenReturn(retPage);
mockMvc.perform(get("/contacts"))
.andExpect(status().is2xxSuccessful())
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java
index 91788ba..f3ed1c4 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/ContactServiceTest.java
@@ -49,7 +49,7 @@
Page<VwDetailedContact> mockPaged = MockDataHelper.mockVDetailedContactPage();
when(detailedContactRepository.findAll(any(Pageable.class))).thenReturn(mockPaged);
Page<VwDetailedContact> retPage = contactService.findDetailedContacts(
- null, null, null, PageRequest.of(0, 20));
+ null, null, null, null, false, false, PageRequest.of(0, 20));
assertEquals(mockPaged.getTotalElements(), retPage.getTotalElements());
}