summaryrefslogtreecommitdiffstats
path: root/portal-BE/src/main/java
diff options
context:
space:
mode:
authorDominik Mizyn <d.mizyn@samsung.com>2019-08-27 12:06:34 +0200
committerDominik Mizyn <d.mizyn@samsung.com>2019-08-27 12:06:43 +0200
commite977510f26b63b1955bae683bbf348dbbc157f80 (patch)
treea6baa521ad6e13906b195f62644f9033115927f8 /portal-BE/src/main/java
parent08cdfa25a5a781673c78f7ec33c23d03164e197a (diff)
Tests Coverage up
Tests Coverage up Issue-ID: PORTAL-710 Change-Id: Iac9e4203613930b905779b45bab83ddfe82bea74 Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'portal-BE/src/main/java')
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java10
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/UserController.java2
-rw-r--r--portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java9
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java21
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java25
5 files changed, 36 insertions, 31 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java b/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java
index 8f2e50e6..90ea0680 100644
--- a/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java
+++ b/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java
@@ -107,7 +107,7 @@ public class LanguageController {
response.setStatus(PortalRestStatusEnum.OK);
} else {
response.setMessage("FAILURE");
- response.setResponse("User for id:" + userId + " do not exist");
+ response.setResponse("User for id: " + userId + " do not exist");
response.setStatus(PortalRestStatusEnum.ERROR);
}
} catch (Exception e) {
@@ -120,11 +120,11 @@ public class LanguageController {
}
@GetMapping(value = "/languageSetting/user/{loginId}", produces = MediaType.APPLICATION_JSON_VALUE)
- public FnLanguage getUserLanguage(@PathVariable("loginId") final Long loginId) {
- if (fnUserService.getUser(loginId).isPresent()) {
- return Optional.of(fnUserService.getUser(loginId).get().getLanguageId()).orElse(new FnLanguage());
+ public FnLanguageDto getUserLanguage(final Principal principal, @PathVariable("loginId") final Long loginId) {
+ if (fnUserService.existById(loginId)) {
+ return fnLanguageMapper.fnLanguageToDto(Optional.of(fnUserService.getUser(loginId).get().getLanguageId()).orElse(new FnLanguage()));
}
- return new FnLanguage();
+ return new FnLanguageDto();
}
@PostMapping(value = "/language", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/UserController.java b/portal-BE/src/main/java/org/onap/portal/controller/UserController.java
index d514dfae..d339e455 100644
--- a/portal-BE/src/main/java/org/onap/portal/controller/UserController.java
+++ b/portal-BE/src/main/java/org/onap/portal/controller/UserController.java
@@ -111,7 +111,7 @@ public class UserController {
user.setMiddleName(profileDetail.getMiddleName());
user.setLoginId(profileDetail.getLoginId());
if (!HIDDEN_DEFAULT_PASSWORD.equals(profileDetail.getLoginPassword())) {
- user.setLoginPwd(CipherUtil.encryptPKC(profileDetail.getLoginPassword()));
+ user.setLoginPwd(CipherUtil.encryptPKC(profileDetail.getLoginPassword(), "AGLDdG4D04BKm2IxIWEr8o==!"));
}
userService.saveFnUser(principal, user);
// Update user info in the session
diff --git a/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java b/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java
index 458cc669..8dbfb70f 100644
--- a/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java
+++ b/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java
@@ -58,5 +58,12 @@ public interface FnUserDao extends JpaRepository<FnUser, Long> {
FnUser getOne(Long integer);
@Query
- Optional<List<FnUser>> getUsersByOrgUserId(@Param("orgIds") String orgIds);
+ Optional<List<FnUser>> getUserWithOrgUserId(final @Param("orgId") String orgId);
+
+ @Query
+ Optional<List<FnUser>> getUsersByOrgIds(final @Param("orgIds") List<String> orgIds);
+
+ @Query
+ Optional<List<FnUser>> getActiveUsers();
+
}
diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java
index cbca44c1..1399dd5c 100644
--- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java
+++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java
@@ -43,7 +43,6 @@ package org.onap.portal.domain.db.fn;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Set;
-import java.util.UUID;
import java.util.stream.Collectors;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -58,6 +57,8 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@@ -72,7 +73,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;
-import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.SafeHtml;
import org.onap.portal.domain.db.cr.CrReportFileHistory;
import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement;
@@ -148,13 +148,18 @@ CREATE TABLE `fn_user` (
)
*/
-@NamedNativeQueries({
- @NamedNativeQuery(
- name = "getUsersByOrgUserId",
- query = "SELECT * FROM FnUser WHERE where org_user_id in :orgIds"
+@NamedQueries({
+ @NamedQuery(
+ name = "FnUser.getUserWithOrgUserId",
+ query = "FROM FnUser WHERE orgUserId = :orgId"),
+ @NamedQuery(
+ name = "FnUser.getActiveUsers",
+ query = "FROM FnUser WHERE activeYn = 'Y'"),
+ @NamedQuery(
+ name = "FnUser.getUsersByOrgIds",
+ query = "FROM FnUser WHERE orgUserId IN :orgIds"
)
})
-
@Table(name = "fn_user", indexes = {
@Index(name = "fn_user_address_id", columnList = "address_id"),
@Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
@@ -350,7 +355,7 @@ public class FnUser implements UserDetails {
private boolean guest;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
private Set<CrReportFileHistory> crReportFileHistorie;
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<FnRole> fnRoles;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<FnMenuFunctional> fnRoleList;
diff --git a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java
index aedac493..8c5806ea 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java
@@ -59,7 +59,7 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class FnUserService implements UserDetailsService {
- private final FnUserDao fnUserDao;
+ private FnUserDao fnUserDao;
@Autowired
public FnUserService(FnUserDao fnUserDao) {
@@ -71,7 +71,7 @@ public class FnUserService implements UserDetailsService {
}
@Override
- public FnUser loadUserByUsername(String username) throws UsernameNotFoundException {
+ public FnUser loadUserByUsername(final String username) throws UsernameNotFoundException {
Optional<FnUser> fnUser = fnUserDao.findByLoginId(username);
if (fnUser.isPresent()) {
return fnUser.get();
@@ -80,36 +80,29 @@ public class FnUserService implements UserDetailsService {
}
}
- public Optional<FnUser> getUser(Long id) {
+ public Optional<FnUser> getUser(final Long id) {
return Optional.of(fnUserDao.getOne(id));
}
List<FnUser> getUserWithOrgUserId(final String orgUserIdValue){
- Optional<List<FnUser>> fnUsers = Optional.of(fnUserDao.findAll()
- .stream()
- .filter(fnUser -> orgUserIdValue.equals(fnUser.getOrgUserId()))
- .collect(Collectors.toList()));
- return fnUsers.orElse(new ArrayList<>());
+ return fnUserDao.getUserWithOrgUserId(orgUserIdValue).orElse(new ArrayList<>());
}
- List<FnUser> getUsersByOrgIdsNotificationsResult(List<String> orgIds){
+ List<FnUser> getUsersByOrgIds(final List<String> orgIds){
String ids = "(" + orgIds.stream().map(s -> "'" + s + "'").collect(Collectors.joining()) + ")";
- return fnUserDao.getUsersByOrgUserId(ids).orElse(new ArrayList<>());
+ return fnUserDao.getUsersByOrgIds(orgIds).orElse(new ArrayList<>());
}
- List<FnUser> getUsersByOrgIdsNotificationsResult(String orgIds){
- return fnUserDao.getUsersByOrgUserId(orgIds).orElse(new ArrayList<>());
- }
List<FnUser> getActiveUsers(){
- return fnUserDao.findAll().stream().filter(fnUser -> "Y".equals(fnUser.getActiveYn())).collect(Collectors.toList());
+ return fnUserDao.getActiveUsers().orElse(new ArrayList<>());
}
- public void deleteUser(FnUser fnUser){
+ public void deleteUser(final FnUser fnUser){
fnUserDao.delete(fnUser);
}
- public boolean existById(Long userId) {
+ public boolean existById(final Long userId) {
return fnUserDao.existsById(userId);
}
}