dataConsumption = dataConsumptionRepository.findAllByUserIdAndStartDateAndEndDate(userid, start, end,
communityid);
emr = new ElectricMeterReading(timeZone);
diff --git a/gecoregistration/src/main/java/it/enea/cruise/controller/MailController.java b/gecoregistration/src/main/java/it/enea/cruise/controller/MailController.java
index ec78d47fdc31dccc7e71dbd2ad2564f24c937a5c..328d4307894477c5e78aef428c79388c59ed842f 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/controller/MailController.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/controller/MailController.java
@@ -22,7 +22,7 @@ import io.swagger.annotations.Api;
import it.enea.cruise.dto.LocalUserDTO;
import it.enea.cruise.model.user.User;
import it.enea.cruise.service.idp.IdpProvider;
-import it.enea.cruise.repositories.UserRepository;
+import it.enea.cruise.repositories.user.UserRepository;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/controller/QueryController.java b/gecoregistration/src/main/java/it/enea/cruise/controller/QueryController.java
index 2e58d080f37abb06e329b519424c8ef657ee141e..3fe4511cf57b22ca6ce39d297782b73afa1ad2d2 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/controller/QueryController.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/controller/QueryController.java
@@ -20,30 +20,30 @@ import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import it.enea.cruise.dto.ParametricQueryDTO;
import it.enea.cruise.dto.QueryParameterDTO;
-import it.enea.cruise.model.parametricQuery.ParametricQuery;
+import it.enea.cruise.model.user.ParametricQuery;
import it.enea.cruise.model.user.User;
-import it.enea.cruise.service.parametricQuery.LocalQueryParameterInterface;
-import it.enea.cruise.service.parametricQuery.ParametricQueryInterface;
+import it.enea.cruise.repositories.user.LocalQueryParameterRepository;
+import it.enea.cruise.repositories.user.ParametricQueryRepository;
import it.enea.cruise.service.parametricQuery.ParametricQueryManager;
-import it.enea.cruise.repositories.UserRepository;
-import it.enea.cruise.model.parametricQuery.LocalQueryParameter;
+import it.enea.cruise.repositories.user.UserRepository;
+import it.enea.cruise.model.user.LocalQueryParameter;
import lombok.extern.log4j.Log4j2;
@RestController
@Api(value = "QueryController")
@EnableTransactionManagement
-@Transactional("dataTransactionManagerIDP")
+/*@Transactional("dataTransactionManagerIDP")*/
@Log4j2
public class QueryController {
@Autowired
- LocalQueryParameterInterface lqpInterface;
+ LocalQueryParameterRepository lqpInterface;
@Autowired
ParametricQueryManager pqm;
@Autowired
- ParametricQueryInterface pqueryInterface;
+ ParametricQueryRepository pqueryInterface;
@Autowired
IdpProvider idpClientManager;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/controller/StructureController.java b/gecoregistration/src/main/java/it/enea/cruise/controller/StructureController.java
index ff09dcfc1943bd58a64b0a02dcd29580b864d1fd..85e08e9bda499c6ed8350e8d531f3e51d09439ac 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/controller/StructureController.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/controller/StructureController.java
@@ -39,13 +39,13 @@ import it.enea.cruise.dto.FieldDTO;
import it.enea.cruise.dto.FormDTO;
import it.enea.cruise.dto.MetadataDTO;
import it.enea.cruise.dto.TableMetadataDTO;
-import it.enea.cruise.model.structure.DescriptionDTO;
+import it.enea.cruise.dto.DescriptionDTO;
import it.enea.cruise.model.structure.ForeignKey;
-import it.enea.cruise.model.structure.TableCommentDTO;
+import it.enea.cruise.dto.TableCommentDTO;
import it.enea.cruise.model.structure.VwTableMetadata;
import it.enea.cruise.model.user.User;
-import it.enea.cruise.service.structure.ForeignKeyInterface;
-import it.enea.cruise.service.structure.TableMetadataInterface;
+import it.enea.cruise.repositories.user.ForeignKeyRepository;
+import it.enea.cruise.repositories.user.TableMetadataRepository;
import it.enea.cruise.repositories.DTOManager;
import lombok.extern.log4j.Log4j2;
@@ -54,10 +54,10 @@ import lombok.extern.log4j.Log4j2;
public class StructureController {
@Autowired
- TableMetadataInterface tmInterface;
+ TableMetadataRepository tmInterface;
@Autowired
- ForeignKeyInterface fkInterface;
+ ForeignKeyRepository fkInterface;
@Autowired
DTOManager dtoManager;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/controller/UserController.java b/gecoregistration/src/main/java/it/enea/cruise/controller/UserController.java
index bb367c8dc06714beb86d6ec2d79f80f82c68a623..eadd1315c4b48f4acc339858478e3b6dd1a49d61 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/controller/UserController.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/controller/UserController.java
@@ -12,9 +12,11 @@ import java.util.regex.Pattern;
import javax.mail.MessagingException;
+import ch.qos.logback.core.util.StringCollectionUtil;
import it.enea.scp.idp.sdk.model.UserDto;
import it.enea.cruise.service.idp.IdpProvider;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
@@ -30,8 +32,6 @@ import org.springframework.web.bind.annotation.RestController;
import org.json.JSONObject;
-import org.springframework.util.StringUtils;
-
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -46,14 +46,14 @@ import it.enea.cruise.model.user.Role;
import it.enea.cruise.model.user.User;
import it.enea.cruise.model.user.UserCommunity;
import it.enea.cruise.model.user.UserRole;
-import it.enea.cruise.model.user.UserToken;
-import it.enea.cruise.service.structure.TableMetadataInterface;
-import it.enea.cruise.repositories.CommunityRepository;
-import it.enea.cruise.repositories.UserRepository;
+import it.enea.cruise.dto.UserToken;
+import it.enea.cruise.repositories.user.TableMetadataRepository;
+import it.enea.cruise.repositories.user.CommunityRepository;
+import it.enea.cruise.repositories.user.UserRepository;
import it.enea.cruise.repositories.DTOManager;
-import it.enea.cruise.repositories.RoleRepository;
-import it.enea.cruise.repositories.UserCommunityRepository;
-import it.enea.cruise.repositories.UserRoleRepository;
+import it.enea.cruise.repositories.user.RoleRepository;
+import it.enea.cruise.repositories.user.UserCommunityRepository;
+import it.enea.cruise.repositories.user.UserRoleRepository;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -65,7 +65,7 @@ import lombok.extern.log4j.Log4j2;
* User controller for exposing REST API calls This class manages all the
* methods for managing both users and communities in the Energy Community
* environment.
- *
+ *
* It connects directly to User and Community entities and to the Identiy
* Provider tools developed by ENEA.
*
@@ -76,123 +76,120 @@ import lombok.extern.log4j.Log4j2;
@RestController
@Api(value = "UserController")
-@Transactional("userTransactionManagerIDP")
+@Transactional
@Log4j2
public class UserController {
- @Value("${testingPhase}")
- private Boolean testingPhase;
-
- @Autowired
- UserRoleRepository userRoleInterface;
-
- @Autowired
- UserRepository userInterface;
-
- @Autowired
- CommunityRepository communityInterface;
-
- @Autowired
- UserCommunityRepository userCommunityInterface;
-
- @Autowired
- RoleRepository roleInterface;
-
- @Autowired
- TableMetadataInterface tmInterface;
-
- @Autowired
- IdpProvider idpClientManager;
-
- @Autowired
- DTOManager dTOManager;
-
- @Autowired
- MailController jmc;
-
- @Value("${communityRoleAdmin}")
- private String communityRoleAdmin;
-
- @Value("${oracleRoleAdmin}")
- private String oracleRoleAdmin;
-
- @Value("${platformRoleAdmin}")
- private String platformRoleAdmin;
-
- @Value("${stakeHolderRole}")
- private String stakeHolderRole;
-
- @Value("${communityMemberRole}")
- private String communityMemberRole;
-
- @Value("${idp.clientSecret}")
- private String secret;
-
- List users = new ArrayList();
-
- /**
- * Returns the list of the users in the DB This method will be removed soon
- * because the lackness of secutiry. In fact, it does not evaluate the role of
- * the requester and does not select the community the users belong to.
- *
- * @param: null
- * @exception: Return an Internal Server error in case of exception
- *
- */
- @Deprecated
- @GetMapping("/ListAllUsers")
- public ResponseEntity> getAllUsers() {
- users = new ArrayList();
- try {
- userInterface.findAll().forEach(users::add);
- } catch (Exception e) {
- return new ResponseEntity(e.getLocalizedMessage(),
- // headers,
- HttpStatus.INTERNAL_SERVER_ERROR);
- }
- return new ResponseEntity>(users, HttpStatus.OK);
- }
-
-
- /**
- * Returns the list of the users in the DB This method will be removed soon
- * because the lackness of secutiry. In fact, it does not evaluate the role of
- * the requester and does not select the community the users belong to.
- *
- * @param: null
- * @exception: Return an Internal Server error in case of exception
- *
- */
-
- @GetMapping("/community/listAllCommunities")
- public ResponseEntity> getAllCommunities() {
- List communities = new ArrayList();
- try {
- List communitiesTemp = communityInterface.findAll();
- for (Community c : communitiesTemp) {
- CommunityDTO cDTO = dTOManager.communityDTO(c);
- communities.add(cDTO);
- }
- } catch (Exception e) {
- return new ResponseEntity(e.getLocalizedMessage(),
- // headers,
- HttpStatus.INTERNAL_SERVER_ERROR);
- }
- return new ResponseEntity>(communities, HttpStatus.OK);
- }
-
-
- /**
- * Creates or updates a user from a JWT valid token This method will be removed
- * because it uses the KeyCloak identity provided. At the moment, it is
- * maintained for compatibility purposes.
- *
- * @params: String token
- * @return: The user if the creation or update is successful
- * @return: Forbidden if the token is not valid
- * @exception: Return an Internal Server error in case of exception
- *
- */
+ @Value("${testingPhase}")
+ private Boolean testingPhase;
+
+ @Autowired
+ UserRoleRepository userRoleInterface;
+
+ @Autowired
+ UserRepository userInterface;
+
+ @Autowired
+ CommunityRepository communityInterface;
+
+ @Autowired
+ UserCommunityRepository userCommunityInterface;
+
+ @Autowired
+ RoleRepository roleInterface;
+
+ @Autowired
+ TableMetadataRepository tmInterface;
+
+ @Autowired
+ IdpProvider idpClientManager;
+
+ @Autowired
+ DTOManager dTOManager;
+
+ @Autowired
+ MailController jmc;
+
+ @Value("${communityRoleAdmin}")
+ private String communityRoleAdmin;
+
+ @Value("${oracleRoleAdmin}")
+ private String oracleRoleAdmin;
+
+ @Value("${platformRoleAdmin}")
+ private String platformRoleAdmin;
+
+ @Value("${stakeHolderRole}")
+ private String stakeHolderRole;
+
+ @Value("${communityMemberRole}")
+ private String communityMemberRole;
+
+ @Value("${idp.clientSecret}")
+ private String secret;
+
+ List users = new ArrayList();
+
+ /**
+ * Returns the list of the users in the DB This method will be removed soon
+ * because the lackness of secutiry. In fact, it does not evaluate the role of
+ * the requester and does not select the community the users belong to.
+ *
+ * @param: null
+ * @exception: Return an Internal Server error in case of exception
+ */
+ @Deprecated
+ @GetMapping("/ListAllUsers")
+ public ResponseEntity> getAllUsers() {
+ users = new ArrayList();
+ try {
+ userInterface.findAll().forEach(users::add);
+ } catch (Exception e) {
+ return new ResponseEntity(e.getLocalizedMessage(),
+ // headers,
+ HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ return new ResponseEntity>(users, HttpStatus.OK);
+ }
+
+
+ /**
+ * Returns the list of the users in the DB This method will be removed soon
+ * because the lackness of secutiry. In fact, it does not evaluate the role of
+ * the requester and does not select the community the users belong to.
+ *
+ * @param: null
+ * @exception: Return an Internal Server error in case of exception
+ */
+
+ @GetMapping("/community/listAllCommunities")
+ public ResponseEntity> getAllCommunities() {
+ List communities = new ArrayList();
+ try {
+ List communitiesTemp = communityInterface.findAll();
+ for (Community c : communitiesTemp) {
+ CommunityDTO cDTO = dTOManager.communityDTO(c);
+ communities.add(cDTO);
+ }
+ } catch (Exception e) {
+ return new ResponseEntity(e.getLocalizedMessage(),
+ // headers,
+ HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ return new ResponseEntity>(communities, HttpStatus.OK);
+ }
+
+
+ /**
+ * Creates or updates a user from a JWT valid token This method will be removed
+ * because it uses the KeyCloak identity provided. At the moment, it is
+ * maintained for compatibility purposes.
+ *
+ * @params: String token
+ * @return: The user if the creation or update is successful
+ * @return: Forbidden if the token is not valid
+ * @exception: Return an Internal Server error in case of exception
+ */
/*@ApiOperation(value = "Create or update user from KEYCLOAK token", response = User.class, tags = "")
@PostMapping("/userFromToken")
@@ -207,13 +204,13 @@ public class UserController {
try {
*//*
- * Check if the token is valid connecting to remote keycloak provider.
- *//*
+ * Check if the token is valid connecting to remote keycloak provider.
+ *//*
Boolean isValid = false;
*//*
- * Remove the usage of the keycloak manager for this application.
- * And returns always an error on interrogating this function
- *//*
+ * Remove the usage of the keycloak manager for this application.
+ * And returns always an error on interrogating this function
+ *//*
//km.isValidToken(token);
if (isValid || testingPhase) {
@@ -224,9 +221,9 @@ public class UserController {
if (userTempFromDB == null) {
*//*
- * The user does not exist on the DB but the token is valid. => user has to be
- * created on the DB
- *//*
+ * The user does not exist on the DB but the token is valid. => user has to be
+ * created on the DB
+ *//*
for (String localRole : userTemp.getKeycloakRoles()) {
Role dbRole = roleInterface.findByRolename(localRole);
if (dbRole.getId() > 0) {
@@ -284,456 +281,442 @@ public class UserController {
}
*/
- @ApiOperation(value = "Return a list of users from their email", response = User.class, tags = "")
- @GetMapping("/userFromEmail")
- public ResponseEntity getUserDTOFromEmail(
- @ApiParam(name = "email", type = "String", value = "Subject string", example = "", required = true) @RequestParam("email") String email) {
-
- UserDto user = idpClientManager.getUserByEmail(email);
- return new ResponseEntity(user,
- // headers,
- HttpStatus.CREATED);
- }
-
-
- /**
- * Returns a user from the Subject code At the moment, it just extact
- * information about the user from the subject. It is not connected to the
- * Identity Provider, at the moment, so the ressult contains only a userid and a
- * subject.
- *
- * @param: String subject code
- * @return: The user if found
- * @return: NotFound if the user does not exist on DB
- *
- */
- @ApiOperation(value = "Return a list of users from their subject code", response = User.class, tags = "")
- @GetMapping("/userFromSubject")
- public ResponseEntity getUserDTOFromSubject(
- @ApiParam(name = "subject", type = "String", value = "Subject string", example = "", required = true) @RequestParam("subject") String subject) {
- User user;
- LocalUserDTO lUserDTO = new LocalUserDTO();
- try {
- user = userInterface.findBySubject(subject);
- //String email = encryptionManager.decrypt(user.getSubject());
- UserDto userDto = idpClientManager.getUserByEmail(user.getSubject());
- user.mergeWithDto(userDto);
-
- lUserDTO = dTOManager.userDTO(user);
-
- } catch (Exception e) {
- log.info(e.getLocalizedMessage());
- return new ResponseEntity("User does not exist in DB",
- // headers,
- HttpStatus.NOT_FOUND);
-
- }
- return new ResponseEntity(lUserDTO,
- // headers,
- HttpStatus.FOUND);
- }
-
- /**
- * Register a user from the simple Registration form
- *
- * @params: the User representation coming from the registration form
- * @return: The user if created
- * @return: Conflict if the user already exists on DB or on KeyCloak
- *
- */
- // @ApiOperation(value = "Register a user from form data", response =
- // User.class, tags = "")
-
- @PostMapping("/user/remoteLogin")
- public ResponseEntity remoteLogin(
- @RequestParam String token ){
-
- System.out.println(token.toString());
-
- return new ResponseEntity(token.toString(), HttpStatus.OK);
- }
-
- @GetMapping("/user/remoteLogin")
- public ResponseEntity getRemoteLogin(
- @RequestParam String token){
-
- System.out.println(token.toString());
-
- return new ResponseEntity(token.toString(), HttpStatus.OK);
- }
-
-
- @PostMapping("/user/register")
- public ResponseEntity registerFromForm(
- @ApiParam(name = "user", type = "User", value = "User representation from theinput form", example = "", required = true)
- @RequestBody LocalUserDTO user) {
- /*
- * Controllo che ci sia almeno la mail.
- */
- if (user.getEmail().isEmpty()) {
- ResultMessage msg = new ResultMessage(false, "The user has not email" );
- return new ResponseEntity(msg, HttpStatus.OK);
- }
-
- /*
- * Controllo se l'utente esiste gia' sui due DB o almeno su IDP
- */
-
- UserDto userIDP = idpClientManager.getUserByEmail(user.getEmail());
-
- if (userIDP == null) {
- /*
- * L'utente non esiste su IDP e quindi posso procedere alla registrazione
- * prima su IDP per ottenere il subject
- */
-
- UserDto uDto = new UserDto();
- uDto.setEmail(user.getEmail());
- uDto.setName(user.getName());
- uDto.setSurname(user.getSurname());
- uDto.setPassword(user.getPassword());
- uDto.setPasswordConfirm(user.getPassword());
- uDto.setEmailConfirmed(true);
- uDto.setRole("Citizen");
- uDto.setOrganization("EnergyCommunity");
-
- Boolean registerdonIDP = idpClientManager.createUser(uDto);
- if (!registerdonIDP) {
- log.info("Error on registering on IDP");
- ResultMessage msg = new ResultMessage(false, "Error on registering on IDP" );
- return new ResponseEntity(msg, HttpStatus.OK);
- }else {
- uDto= idpClientManager.getUserByEmail(uDto.getEmail());
- }
-
- /*
- * Adesso creo l'utente locale con le informazioni e le comunita'.
- */
-
- User tmpUser = new User();
- tmpUser.setSubject(uDto.getUuid());
- user.setSubject(uDto.getUuid());
- // Inserisco le comunita
- for (CommunityDTO cDto : user.getUsercommunities()) {
- Community c = communityInterface.findByCommunityid(cDto.getCommunityid());
- UserCommunity uc1 = new UserCommunity();
- uc1.setCommunity(c);
- uc1.setUser(tmpUser);
- uc1.setWallet(cDto.getWallet());
- uc1.setSubscriptiondate(new Date(System.currentTimeMillis()));
- uc1.setActive(true);
- tmpUser.setSingleUsercommunity(uc1);
- Role tmpRole = roleInterface.getById(new Long(2));
- UserRole ur = new UserRole();
- ur.setCommunity(c);
- ur.setUser(tmpUser);
- ur.setRole(tmpRole);
- tmpUser.setSingleUserRole(ur);
- }
-
- tmpUser = userInterface.save(tmpUser);
- log.info("user saved, probably... the number of available users is " + userInterface.count());
-
- user.setUserid(tmpUser.getUserid());
-
-
-
- } else {
- log.info("User with email " + user.getEmail() + " already exists");
- ResultMessage msg = new ResultMessage(false, "User with email " + user.getEmail() + " already exists" );
-
- return new ResponseEntity(msg, HttpStatus.OK);
- }
-
- //OK. Se sono arrivato qui posso mandare la mail di conferma
- log.info("Sending activation email to " + user.getEmail());
-
-
-
- try {
- jmc.sendMessageUsingFreemarkerTemplate(user);
- } catch (IOException | TemplateException | MessagingException e) {
- log.info("Mailing failed");
- log.info(e.getLocalizedMessage());
- }
- ResultMessage msg = new ResultMessage(true, "User created" );
- return new ResponseEntity(msg, HttpStatus.OK);
- }
-
- /**
- * Returns the number of participants in a a community managed by the
- * owner of the token
- *
- * @params: The admin's token
- * @return: The number of participants, if the user is and admin
- * @return: A forbidden message otherwise
- *
- */
- @ApiOperation(value = "Get the number of users in a community from the administrator's token", response = User.class, tags = "")
- @PostMapping("/getNumberOfParticipants")
- ResponseEntity> getNumberOfParticipants(
- @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = true) @RequestParam String token) {
-
-
- User u = new User();
- Boolean isValid = idpClientManager.isValid(token);
- Integer result = 0;
-
- if (isValid) {
- User userdto = idpClientManager.getUserByToken(token);
-
- u = userInterface.findBySubject(userdto.getUuid());
- if (u.hasRole(communityRoleAdmin) || u.hasRole(oracleRoleAdmin) || u.hasRole(platformRoleAdmin)) {
- for (UserCommunity c : u.getUsercommunities()) {
- result = userInterface.countBySubjectIsNotNullAndCommunityId(c.getId().getCommunityId());
- }
- }
- }else {
- return new ResponseEntity("User is not an addmin",
- HttpStatus.FORBIDDEN);
- }
- return new ResponseEntity (result, HttpStatus.OK);
- }
-
-
- /**
- * Returns a user from a wallet if the token owner is an admin for the community
- *
- * @params: The wallet
- * @params: the admin's token
- * @return: The user, if the if the token belongs to an admin
- * @return: A forbidden message otherwise
- *
- */
- @ApiOperation(value = "Get a user in a community from the wallet(s)", response = User.class, tags = "")
- @PostMapping("/getUserFromWallet")
- ResponseEntity> getUserFromWallet(
- @RequestBody List wallets,
- @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = true) @RequestParam String token)
- {
- LocalUserDTO lUserDTO = new LocalUserDTO();
-
- User u = new User();
- Boolean isValid = idpClientManager.isValid(token);
-
- Map> resultMap = new HashMap>();
-
- if (isValid) {
- User userdto = idpClientManager.getUserByToken(token);
-
- u = userInterface.findBySubject(userdto.getUuid());
- if (u.hasRole(communityRoleAdmin) || u.hasRole(oracleRoleAdmin) || u.hasRole(platformRoleAdmin)) {
- for (Community c : u.getCommunities()) {
- List result = new ArrayList();
- for (String wallet : wallets) {
- result.addAll(userInterface.findFromWalletAndCommunityId(wallet, c.getCommunityid()));
- }
- if (result.size()> 0) {
- u = result.get(0); //qualcosa non va se ne trovo piu' di uno
- UserDto userdtoNew = idpClientManager.getUserFromUUID(
- u.getSubject());
- u.mergeWithDto(userdtoNew);
- lUserDTO = dTOManager.userDTO(u);
- return new ResponseEntity (lUserDTO, HttpStatus.OK);
- }
- }
- }
- if (u.hasRole(stakeHolderRole) || u.hasRole(communityMemberRole)) {
- for (Community c : u.getCommunities()) {
- List result = new ArrayList();
- for (String wallet : wallets) {
- result.addAll(userInterface.findFromWalletAndCommunityId(wallet, c.getCommunityid()));
- }
- if (result.size()> 0) {
- u = result.get(0);
- UserDto userdtoNew = idpClientManager.getUserByEmail(
- u.getSubject());
- u.mergeWithDto(userdtoNew);
- lUserDTO.setEmail(u.getEmail());
- lUserDTO.setPhone(u.getPhone());
- return new ResponseEntity (lUserDTO, HttpStatus.OK);
- }
- }
- }
-
-
- }else {
- return new ResponseEntity("User is not an addmin",
- HttpStatus.FORBIDDEN);
- }
- return new ResponseEntity (lUserDTO, HttpStatus.OK);
- }
-
- /**
- * Returns the list of communities the user belongs to It uses the Keycloak
- * application for controlling the requester's roles. This methd shall be
- * duplicated for the Identity Provider tool
- *
- * @param: the JWT token of the user
- * @return: The list of the user communities
- * @return: Forbidden if the token is not valid
- * @return: Forbidden if the user is not an administrator
- *
- */
- @ApiOperation(value = "Get all users in a community from the administrator's token", response = User.class, tags = "")
- @PostMapping("/getusercommunities")
- ResponseEntity> getUserCommunities(
- @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = true) @RequestParam String token) {
-
-
- User u = new User();
- List usersInCommunity = new ArrayList();
- List listOfUsers = new ArrayList();
- Boolean isValid = idpClientManager.isValid(token);
-
-
- if (isValid) {
- User userdto = idpClientManager.getUserByToken(token);
-
- u = userInterface.findBySubject(userdto.getUuid());
- if (u.hasRole(communityRoleAdmin) || u.hasRole(oracleRoleAdmin) || u.hasRole(platformRoleAdmin)) {
- for (UserCommunity c : u.getUsercommunities()) {
- usersInCommunity.addAll(userInterface.findBySubjectIsNotNullAndActiveIsTrueAndCommunityId(c.getId().getCommunityId()));
- }
-
- for (User uTmp : usersInCommunity) {
-
- String subejct = uTmp.getSubject();
- log.info("email: " + subejct);
- if(subejct != null && !subejct.isEmpty()) {
- UserDto tmpUserDto = idpClientManager.getUserByEmail(subejct);
- if (tmpUserDto != null ) {
- uTmp.mergeWithDto(tmpUserDto);
- LocalUserDTO lUserDTO = dTOManager.userDTO(uTmp);
- lUserDTO.setEmail(tmpUserDto.getEmail());
- listOfUsers.add(lUserDTO);
- }
- }
- }
-
-
-
-
-
- } else {
- return new ResponseEntity("User is not an addmin",
- HttpStatus.FORBIDDEN);
- }
- } else {
- return new ResponseEntity("Provided token is not valid ", // headers,
- HttpStatus.FORBIDDEN);
- }
- return new ResponseEntity>(listOfUsers, // headers,
- HttpStatus.OK);
- }
-
-
- @ApiOperation(value = "Generate subject", response = String.class, tags = "")
- @PostMapping("/generateSubject")
- @Deprecated
- ResponseEntity generateSubject(
- @ApiParam(name = "mail", type = "String", value = "The user's email", example = "", required = false)
- @RequestBody String email){
- //String subject = encryptionManager.encrypt(email);
-
- return new ResponseEntity ("", HttpStatus.OK);
- }
-
-
- @ApiOperation(value = "Generate email", response = String.class, tags = "")
- @PostMapping("/returnEmail")
- @Deprecated
- ResponseEntity generateEmail(
- @ApiParam(name = "Subject", type = "String", value = "The user's subject", example = "", required = false)
- @RequestBody String subject){
- //String email = encryptionManager.decrypt(subject);
-
- return new ResponseEntity ("", HttpStatus.OK);
- }
-
-
- /**
- * Returns the list of users if the requester is a platform admin This method
- * shall be moved for using the Identity Provider tool
- *
- * @param: the JWT token of the user
- * @return: The list of the users
- * @return: Forbidden if the token is not valid
- * @return: Forbidden if the user is not an administrator
- *
- */
-
- @ApiOperation(value = "Get all users if the requester is a platform admin", response = User.class, tags = "")
- @PostMapping("/getusers")
- ResponseEntity> getUsers(
- @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = false) @RequestParam(required = false) String token,
- @ApiParam(name = "Authorization", type = "String", value = "The administrator's token", example = "", required = false) @RequestHeader(name = "Authorization", required = false) String tokenAuth) {
- List users = new ArrayList();
- List resultList = new ArrayList();
- Boolean isValid = false;
- User u = new User();
- User userdto;
- String subject = "";
- if ((token == null || token.length() == 0) && (tokenAuth == null || tokenAuth.length() == 0)) {
- return new ResponseEntity("Token has not been provided", // headers,
- HttpStatus.FORBIDDEN);
- }
- if (token != null) {
- //isValid = km.isValidToken(token);
-
- //if (isValid) {
- /* Ok, I'm using the keycloak manager */
- //subject = JWTManager.getSubject(token);
- //}
- } else {
- isValid = idpClientManager.isValid(tokenAuth);
- if (isValid) {
- userdto = idpClientManager.getUserByToken(tokenAuth);
- subject = userdto.getUuid();
- } else {
- return new ResponseEntity("Provided token is not valid ", // headers,
- HttpStatus.FORBIDDEN);
- }
-
- u = userInterface.findBySubject(userdto.getUuid());
- if (u.hasRole(platformRoleAdmin)) {
- users = userInterface.findBySubjectIsNotNull();
-
- for (User uTmp : users) {
-
- String subjectLocal = uTmp.getSubject();
- if(subjectLocal != null && !subjectLocal.isEmpty()) {
- UserDto tmpUserDto = idpClientManager.getUserByEmail(subjectLocal);
- if (tmpUserDto != null ) {
- uTmp.mergeWithDto(tmpUserDto);
- LocalUserDTO lUserDTO = dTOManager.userDTO(uTmp);
- lUserDTO.setEmail(tmpUserDto.getEmail());
- resultList.add(lUserDTO);
- }
- }
- }
-
-
-
- } else {
- return new ResponseEntity("User is not a " + platformRoleAdmin, // headers,
- HttpStatus.FORBIDDEN);
- }
-
- }
- return new ResponseEntity>(resultList, // headers,
- HttpStatus.OK);
- }
-
- // @ApiOperation(value = "Get all users as the requester is a platform admin",
- // response = User.class, tags = "")
- // @GetMapping("/getusers")
- // ResponseEntity> getgetUsers(
- // @ApiParam(name = "token", type = "String", value = "The administrator's
- // token", example = "", required = true)
- // @RequestParam String token) {
- // return getUsers(token, "");
- // }
+ @ApiOperation(value = "Return a list of users from their email", response = User.class, tags = "")
+ @GetMapping("/userFromEmail")
+ public ResponseEntity getUserDTOFromEmail(
+ @ApiParam(name = "email", type = "String", value = "Subject string", example = "", required = true) @RequestParam("email") String email) {
+
+ UserDto user = idpClientManager.getUserByEmail(email);
+ return new ResponseEntity(user,
+ // headers,
+ HttpStatus.CREATED);
+ }
+
+
+ /**
+ * Returns a user from the Subject code At the moment, it just extact
+ * information about the user from the subject. It is not connected to the
+ * Identity Provider, at the moment, so the ressult contains only a userid and a
+ * subject.
+ *
+ * @param: String subject code
+ * @return: The user if found
+ * @return: NotFound if the user does not exist on DB
+ */
+ @ApiOperation(value = "Return a list of users from their subject code", response = User.class, tags = "")
+ @GetMapping("/userFromSubject")
+ public ResponseEntity getUserDTOFromSubject(
+ @ApiParam(name = "subject", type = "String", value = "Subject string", example = "", required = true) @RequestParam("subject") String subject) {
+ User user;
+ LocalUserDTO lUserDTO = new LocalUserDTO();
+ try {
+ user = userInterface.findBySubject(subject);
+ //String email = encryptionManager.decrypt(user.getSubject());
+ UserDto userDto = idpClientManager.getUserByEmail(user.getSubject());
+ user.mergeWithDto(userDto);
+
+ lUserDTO = dTOManager.userDTO(user);
+
+ } catch (Exception e) {
+ log.info(e.getLocalizedMessage());
+ return new ResponseEntity("User does not exist in DB",
+ // headers,
+ HttpStatus.NOT_FOUND);
+
+ }
+ return new ResponseEntity(lUserDTO,
+ // headers,
+ HttpStatus.FOUND);
+ }
+
+ /**
+ * Register a user from the simple Registration form
+ *
+ * @params: the User representation coming from the registration form
+ * @return: The user if created
+ * @return: Conflict if the user already exists on DB or on KeyCloak
+ */
+ // @ApiOperation(value = "Register a user from form data", response =
+ // User.class, tags = "")
+ @PostMapping("/user/remoteLogin")
+ public ResponseEntity remoteLogin(
+ @RequestParam String token) {
+
+ System.out.println(token.toString());
+
+ return new ResponseEntity(token.toString(), HttpStatus.OK);
+ }
+
+ @GetMapping("/user/remoteLogin")
+ public ResponseEntity getRemoteLogin(
+ @RequestParam String token) {
+
+ System.out.println(token.toString());
+
+ return new ResponseEntity(token.toString(), HttpStatus.OK);
+ }
+
+
+ @PostMapping("/user/register")
+ public ResponseEntity registerFromForm(
+ @ApiParam(name = "user", type = "User", value = "User representation from theinput form", example = "", required = true)
+ @RequestBody LocalUserDTO user) {
+ /*
+ * Controllo che ci sia almeno la mail.
+ */
+ if (user.getEmail().isEmpty()) {
+ ResultMessage msg = new ResultMessage(false, "The user has not email");
+ return new ResponseEntity(msg, HttpStatus.OK);
+ }
+
+ /*
+ * Controllo se l'utente esiste gia' sui due DB o almeno su IDP
+ */
+
+ UserDto userIDP = idpClientManager.getUserByEmail(user.getEmail());
+
+ if (userIDP == null) {
+ /*
+ * L'utente non esiste su IDP e quindi posso procedere alla registrazione
+ * prima su IDP per ottenere il subject
+ */
+
+ UserDto uDto = new UserDto();
+ uDto.setEmail(user.getEmail());
+ uDto.setName(user.getName());
+ uDto.setSurname(user.getSurname());
+ uDto.setPassword(user.getPassword());
+ uDto.setPasswordConfirm(user.getPassword());
+ uDto.setEmailConfirmed(true);
+ uDto.setRole("Citizen");
+ uDto.setOrganization("EnergyCommunity");
+
+ Boolean registerdonIDP = idpClientManager.createUser(uDto);
+ if (!registerdonIDP) {
+ log.info("Error on registering on IDP");
+ ResultMessage msg = new ResultMessage(false, "Error on registering on IDP");
+ return new ResponseEntity(msg, HttpStatus.OK);
+ } else {
+ uDto = idpClientManager.getUserByEmail(uDto.getEmail());
+ }
+
+ /*
+ * Adesso creo l'utente locale con le informazioni e le comunita'.
+ */
+
+ User tmpUser = new User();
+ tmpUser.setSubject(uDto.getUuid());
+ user.setSubject(uDto.getUuid());
+ // Inserisco le comunita
+ for (CommunityDTO cDto : user.getUsercommunities()) {
+ Community c = communityInterface.findById(cDto.getCommunityid()).get();
+ UserCommunity uc1 = new UserCommunity();
+ uc1.setCommunity(c);
+ uc1.setUser(tmpUser);
+ uc1.setWallet(cDto.getWallet());
+ uc1.setSubscriptiondate(new Date(System.currentTimeMillis()));
+ uc1.setActive(true);
+ tmpUser.setSingleUsercommunity(uc1);
+ Role tmpRole = roleInterface.getById(new Long(2));
+ UserRole ur = new UserRole();
+ ur.setCommunity(c);
+ ur.setUser(tmpUser);
+ ur.setRole(tmpRole);
+ tmpUser.setSingleUserRole(ur);
+ }
+
+ tmpUser = userInterface.save(tmpUser);
+ log.info("user saved, probably... the number of available users is " + userInterface.count());
+
+ user.setUserid(tmpUser.getUserid());
+
+
+ } else {
+ log.info("User with email " + user.getEmail() + " already exists");
+ ResultMessage msg = new ResultMessage(false, "User with email " + user.getEmail() + " already exists");
+
+ return new ResponseEntity(msg, HttpStatus.OK);
+ }
+
+ //OK. Se sono arrivato qui posso mandare la mail di conferma
+ log.info("Sending activation email to " + user.getEmail());
+
+
+ try {
+ jmc.sendMessageUsingFreemarkerTemplate(user);
+ } catch (IOException | TemplateException | MessagingException e) {
+ log.info("Mailing failed");
+ log.info(e.getLocalizedMessage());
+ }
+ ResultMessage msg = new ResultMessage(true, "User created");
+ return new ResponseEntity(msg, HttpStatus.OK);
+ }
+
+ /**
+ * Returns the number of participants in a a community managed by the
+ * owner of the token
+ *
+ * @params: The admin's token
+ * @return: The number of participants, if the user is and admin
+ * @return: A forbidden message otherwise
+ */
+ @ApiOperation(value = "Get the number of users in a community from the administrator's token", response = User.class, tags = "")
+ @PostMapping("/getNumberOfParticipants")
+ ResponseEntity> getNumberOfParticipants(
+ @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = true) @RequestParam String token) {
+
+
+ User u = new User();
+ Boolean isValid = idpClientManager.isValid(token);
+ Integer result = 0;
+
+ if (isValid) {
+ User userdto = idpClientManager.getUserByToken(token);
+
+ u = userInterface.findBySubject(userdto.getUuid());
+ if (u.hasRole(communityRoleAdmin) || u.hasRole(oracleRoleAdmin) || u.hasRole(platformRoleAdmin)) {
+ for (UserCommunity c : u.getUsercommunities()) {
+ result = userInterface.countBySubjectIsNotNullAndCommunityId(c.getId().getCommunityId());
+ }
+ }
+ } else {
+ return new ResponseEntity("User is not an addmin",
+ HttpStatus.FORBIDDEN);
+ }
+ return new ResponseEntity(result, HttpStatus.OK);
+ }
+
+
+ /**
+ * Returns a user from a wallet if the token owner is an admin for the community
+ *
+ * @params: The wallet
+ * @params: the admin's token
+ * @return: The user, if the if the token belongs to an admin
+ * @return: A forbidden message otherwise
+ */
+ @ApiOperation(value = "Get a user in a community from the wallet(s)", response = User.class, tags = "")
+ @PostMapping("/getUserFromWallet")
+ ResponseEntity> getUserFromWallet(
+ @RequestBody List wallets,
+ @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = true) @RequestParam String token) {
+ LocalUserDTO lUserDTO = new LocalUserDTO();
+
+ User u = new User();
+ Boolean isValid = idpClientManager.isValid(token);
+
+ Map> resultMap = new HashMap>();
+
+ if (isValid) {
+ User userdto = idpClientManager.getUserByToken(token);
+
+ u = userInterface.findBySubject(userdto.getUuid());
+ if (u.hasRole(communityRoleAdmin) || u.hasRole(oracleRoleAdmin) || u.hasRole(platformRoleAdmin)) {
+ for (Community c : u.getCommunities()) {
+ List result = new ArrayList();
+ for (String wallet : wallets) {
+ result.addAll(userInterface.findFromWalletAndCommunityId(wallet, c.getId()));
+ }
+ if (result.size() > 0) {
+ u = result.get(0); //qualcosa non va se ne trovo piu' di uno
+ UserDto userdtoNew = idpClientManager.getUserFromUUID(
+ u.getSubject());
+ u.mergeWithDto(userdtoNew);
+ lUserDTO = dTOManager.userDTO(u);
+ return new ResponseEntity(lUserDTO, HttpStatus.OK);
+ }
+ }
+ }
+ if (u.hasRole(stakeHolderRole) || u.hasRole(communityMemberRole)) {
+ for (Community c : u.getCommunities()) {
+ List result = new ArrayList();
+ for (String wallet : wallets) {
+ result.addAll(userInterface.findFromWalletAndCommunityId(wallet, c.getId()));
+ }
+ if (result.size() > 0) {
+ u = result.get(0);
+ UserDto userdtoNew = idpClientManager.getUserByEmail(
+ u.getSubject());
+ u.mergeWithDto(userdtoNew);
+ lUserDTO.setEmail(u.getEmail());
+ lUserDTO.setPhone(u.getPhone());
+ return new ResponseEntity(lUserDTO, HttpStatus.OK);
+ }
+ }
+ }
+
+
+ } else {
+ return new ResponseEntity("User is not an addmin",
+ HttpStatus.FORBIDDEN);
+ }
+ return new ResponseEntity(lUserDTO, HttpStatus.OK);
+ }
+
+ /**
+ * Returns the list of communities the user belongs to It uses the Keycloak
+ * application for controlling the requester's roles. This methd shall be
+ * duplicated for the Identity Provider tool
+ *
+ * @param: the JWT token of the user
+ * @return: The list of the user communities
+ * @return: Forbidden if the token is not valid
+ * @return: Forbidden if the user is not an administrator
+ */
+ @ApiOperation(value = "Get all users in a community from the administrator's token", response = User.class, tags = "")
+ @PostMapping("/getusercommunities")
+ ResponseEntity> getUserCommunities(
+ @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = true) @RequestParam String token) {
+
+
+ User u = new User();
+ List usersInCommunity = new ArrayList();
+ List listOfUsers = new ArrayList();
+ Boolean isValid = idpClientManager.isValid(token);
+
+
+ if (isValid) {
+ User userdto = idpClientManager.getUserByToken(token);
+
+ u = userInterface.findBySubject(userdto.getUuid());
+ if (u.hasRole(communityRoleAdmin) || u.hasRole(oracleRoleAdmin) || u.hasRole(platformRoleAdmin)) {
+ for (UserCommunity c : u.getUsercommunities()) {
+ usersInCommunity.addAll(userInterface.findBySubjectIsNotNullAndActiveIsTrueAndCommunityId(c.getId().getCommunityId()));
+ }
+
+ for (User uTmp : usersInCommunity) {
+
+ String subejct = uTmp.getSubject();
+ log.info("email: " + subejct);
+ if (subejct != null && !subejct.isEmpty()) {
+ UserDto tmpUserDto = idpClientManager.getUserByEmail(subejct);
+ if (tmpUserDto != null) {
+ uTmp.mergeWithDto(tmpUserDto);
+ LocalUserDTO lUserDTO = dTOManager.userDTO(uTmp);
+ lUserDTO.setEmail(tmpUserDto.getEmail());
+ listOfUsers.add(lUserDTO);
+ }
+ }
+ }
+
+
+ } else {
+ return new ResponseEntity("User is not an addmin",
+ HttpStatus.FORBIDDEN);
+ }
+ } else {
+ return new ResponseEntity("Provided token is not valid ", // headers,
+ HttpStatus.FORBIDDEN);
+ }
+ return new ResponseEntity>(listOfUsers, // headers,
+ HttpStatus.OK);
+ }
+
+
+ @ApiOperation(value = "Generate subject", response = String.class, tags = "")
+ @PostMapping("/generateSubject")
+ @Deprecated
+ ResponseEntity generateSubject(
+ @ApiParam(name = "mail", type = "String", value = "The user's email", example = "", required = false)
+ @RequestBody String email) {
+ //String subject = encryptionManager.encrypt(email);
+
+ return new ResponseEntity("", HttpStatus.OK);
+ }
+
+
+ @ApiOperation(value = "Generate email", response = String.class, tags = "")
+ @PostMapping("/returnEmail")
+ @Deprecated
+ ResponseEntity generateEmail(
+ @ApiParam(name = "Subject", type = "String", value = "The user's subject", example = "", required = false)
+ @RequestBody String subject) {
+ //String email = encryptionManager.decrypt(subject);
+
+ return new ResponseEntity("", HttpStatus.OK);
+ }
+
+
+ /**
+ * Returns the list of users if the requester is a platform admin This method
+ * shall be moved for using the Identity Provider tool
+ *
+ * @param: the JWT token of the user
+ * @return: The list of the users
+ * @return: Forbidden if the token is not valid
+ * @return: Forbidden if the user is not an administrator
+ */
+
+ @ApiOperation(value = "Get all users if the requester is a platform admin", response = User.class, tags = "")
+ @PostMapping("/getusers")
+ ResponseEntity> getUsers(
+ @ApiParam(name = "token", type = "String", value = "The administrator's token", example = "", required = false) @RequestParam(required = false) String token,
+ @ApiParam(name = "Authorization", type = "String", value = "The administrator's token", example = "", required = false) @RequestHeader(name = "Authorization", required = false) String tokenAuth) {
+ List users = new ArrayList();
+ List resultList = new ArrayList();
+ Boolean isValid = false;
+ User u = new User();
+ User userdto;
+ String subject = "";
+ if ((token == null || token.length() == 0) && (tokenAuth == null || tokenAuth.length() == 0)) {
+ return new ResponseEntity("Token has not been provided", // headers,
+ HttpStatus.FORBIDDEN);
+ }
+ if (token != null) {
+ //isValid = km.isValidToken(token);
+
+ //if (isValid) {
+ /* Ok, I'm using the keycloak manager */
+ //subject = JWTManager.getSubject(token);
+ //}
+ } else {
+ isValid = idpClientManager.isValid(tokenAuth);
+ if (isValid) {
+ userdto = idpClientManager.getUserByToken(tokenAuth);
+ subject = userdto.getUuid();
+ } else {
+ return new ResponseEntity("Provided token is not valid ", // headers,
+ HttpStatus.FORBIDDEN);
+ }
+
+ u = userInterface.findBySubject(userdto.getUuid());
+ if (u.hasRole(platformRoleAdmin)) {
+ users = userInterface.findBySubjectIsNotNull();
+
+ for (User uTmp : users) {
+
+ String subjectLocal = uTmp.getSubject();
+ if (subjectLocal != null && !subjectLocal.isEmpty()) {
+ UserDto tmpUserDto = idpClientManager.getUserByEmail(subjectLocal);
+ if (tmpUserDto != null) {
+ uTmp.mergeWithDto(tmpUserDto);
+ LocalUserDTO lUserDTO = dTOManager.userDTO(uTmp);
+ lUserDTO.setEmail(tmpUserDto.getEmail());
+ resultList.add(lUserDTO);
+ }
+ }
+ }
+
+
+ } else {
+ return new ResponseEntity("User is not a " + platformRoleAdmin, // headers,
+ HttpStatus.FORBIDDEN);
+ }
+
+ }
+ return new ResponseEntity>(resultList, // headers,
+ HttpStatus.OK);
+ }
+
+ // @ApiOperation(value = "Get all users as the requester is a platform admin",
+ // response = User.class, tags = "")
+ // @GetMapping("/getusers")
+ // ResponseEntity> getgetUsers(
+ // @ApiParam(name = "token", type = "String", value = "The administrator's
+ // token", example = "", required = true)
+ // @RequestParam String token) {
+ // return getUsers(token, "");
+ // }
// /**
// * Returns the list of users belonging to a community
@@ -750,489 +733,488 @@ public class UserController {
// return new ResponseEntity>(usersInCommunity, HttpStatus.OK);
// }
- /**
- * Delete the user from DB and ID-Provider
- *
- * @param: User: the user to be deleted
- * @return: True if cancellation is complete
- */
- @ApiOperation(value = "Delete the user.", response = Boolean.class, tags = "")
- @DeleteMapping("/user/delete")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 403, message = "Token is null or not valid"),
- @ApiResponse(code = 500, message = "User cannot delete from DBs"), })
- public ResponseEntity deleteUser(
- @ApiParam(name = "userToken", type = "String", value = "The user's IDP token or email", example = "", required = true) @RequestBody String userToken) {
-
- // log.info("Deleting user with token = {} ", userToken);
- if (userToken == null || userToken == "") {
- log.info("Input is null ");
- return new ResponseEntity(false, HttpStatus.FORBIDDEN);
- }
- Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$",
- Pattern.CASE_INSENSITIVE);
- Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(userToken);
- UserDto userdto = new UserDto();
- Boolean isEmail = false;
- User userDel = new User();
- if (matcher.find()) {
- log.info("Deleting user with email = {} ", userToken);
- userdto = idpClientManager.getUserByEmail(userToken);
- isEmail = true;
+ /**
+ * Delete the user from DB and ID-Provider
+ *
+ * @param: User: the user to be deleted
+ * @return: True if cancellation is complete
+ */
+ @ApiOperation(value = "Delete the user.", response = Boolean.class, tags = "")
+ @DeleteMapping("/user/delete")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 403, message = "Token is null or not valid"),
+ @ApiResponse(code = 500, message = "User cannot delete from DBs"),})
+ public ResponseEntity deleteUser(
+ @ApiParam(name = "userToken", type = "String", value = "The user's IDP token or email", example = "", required = true) @RequestBody String userToken) {
+
+ // log.info("Deleting user with token = {} ", userToken);
+ if (userToken == null || userToken == "") {
+ log.info("Input is null ");
+ return new ResponseEntity(false, HttpStatus.FORBIDDEN);
+ }
+ Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$",
+ Pattern.CASE_INSENSITIVE);
+ Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(userToken);
+ UserDto userdto = new UserDto();
+ Boolean isEmail = false;
+ User userDel = new User();
+ if (matcher.find()) {
+ log.info("Deleting user with email = {} ", userToken);
+ userdto = idpClientManager.getUserByEmail(userToken);
+ isEmail = true;
+
+ }
+ if (idpClientManager.isValid(userToken)) {
+ log.info("Deleting user with token = {} ", userToken);
+ userDel = idpClientManager.getUserByToken(userToken);
+ }
+ if (userDel != null) {
+ Boolean resultIDPRemove = idpClientManager.deleteUser(userDel.getEmail());
+
+ if (!resultIDPRemove) {
+ log.info("Failed to delete user from ID-Provider");
+ return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+ User user = userInterface.findBySubject(userdto.getUuid());
+
+ if (user == null) {
+ log.info("Failed to delete user from DB because the user does not exist");
+ return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ userInterface.delete(user);
+
+ } else if (isEmail) {
+ User user = userInterface.findBySubject(userdto.getUuid());
+ if (user == null) {
+ log.info("Failed to delete user from DB because the user does not exist");
+ return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ userInterface.delete(user);
+ } else {
+ log.info("Provided input is not valid or user not present in IDP", userToken);
+ return new ResponseEntity(false, HttpStatus.FORBIDDEN);
+ }
+ return new ResponseEntity(true, HttpStatus.OK);
+ }
+
+ /**
+ * Login the user by providing user's details if username and password are
+ * correct.
+ *
+ * @param: Username: the user's username
+ * @param: Password: the user's password
+ * @return: a full user if both username and password are correct, an empty user
+ * if not.
+ */
+
+ @ApiOperation(value = "Login the user. Returns Http.OK and User object if username and password are valid, Http.Forbidden otherwise", response = User.class, tags = "")
+ @PostMapping("/user/login")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 403, message = "Username or password are invalid")})
+ ResponseEntity login(
+ @ApiParam(name = "username", type = "String", value = "The username", example = "", required = true) @RequestParam String username,
+ @ApiParam(name = "password", type = "String", value = "The password", example = "", required = true) @RequestParam String password) {
+ if (StringUtils.isBlank(username) || StringUtils.isBlank(username)) {
+ log.info("Username or password are empty");
+ return new ResponseEntity<>(new LocalUserDTO(), HttpStatus.FORBIDDEN);
+ }
+
+ User userdto = idpClientManager.login(username, password);
+ if (userdto == null) {
+ log.info("Wrong username or password");
+ return new ResponseEntity<>(new LocalUserDTO(), HttpStatus.FORBIDDEN);
+ }
+
+ log.info("UUID: " + userdto.getSubject());
+
+ User user = userInterface.findBySubject(userdto.getSubject());
+ if (user == null) {
+ log.info("Adding into local DB");
+ User tempUser = new User();
+ tempUser.setSubject(userdto.getSubject());
+ tempUser.merge(userdto);
+
+ tempUser = userInterface.save(tempUser);
+ LocalUserDTO lUserDTO = dTOManager.userDTO(tempUser);
+
+ return new ResponseEntity(lUserDTO, HttpStatus.OK);
+ }
+ for (Device d : user.getDevices()) {
+ log.info(d.getDevicename());
+ }
+
+ user.merge(userdto);
+
+ LocalUserDTO lUserDTO = dTOManager.userDTO(user);
+ log.info(lUserDTO.toString());
+
+ return new ResponseEntity<>(lUserDTO, HttpStatus.OK);
+ }
+
+ /**
+ * Logout the user using the token
+ *
+ * @param: User Token
+ * @return: True if the user is correctly logged out, false otherwise
+ */
+ @ApiOperation(value = "Logout the user. Returns Http.OK and User object if username and password are valid, Http.Forbidden otherwise", response = Boolean.class, tags = "")
+ @PostMapping("/user/logout")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 500, message = "Logout has failed for unknown causes")})
+ ResponseEntity logout(
+ @ApiParam(name = "token", type = "String", value = "The user's token", example = "", required = true) @RequestParam String token,
+ @RequestHeader(name = "Authorization", required = false) String tokenAuth) {
+ if (StringUtils.isBlank(token)) {
+ if (StringUtils.isBlank(tokenAuth)) {
+ log.info("Token is empty");
+ return new ResponseEntity<>(false, HttpStatus.INTERNAL_SERVER_ERROR);
+ } else
+ token = tokenAuth;
+ }
+ Boolean result = idpClientManager.logout(token);
+
+ if (result) {
+ return new ResponseEntity<>(result, HttpStatus.OK);
+ } else {
+ log.info("Failed to logout");
+ return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+ }
+
+ /**
+ * Check if the token is valid and alive
+ *
+ * @param: User Token
+ * @return: True if the user is the token is valid, false otherwise
+ */
+ @ApiOperation(value = "Check if the token is valid and return a boolean", response = Boolean.class, tags = "")
+ @PostMapping("/user/isTokenValid")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 403, message = "Token not valid"),
+ @ApiResponse(code = 500, message = "Token is null")})
+ ResponseEntity checkToken(
+ @RequestHeader(name = "Authorization", required = false) String token,
+ @ApiParam(name = "token", type = "String", value = "The user's token", example = "", required = false)
+ @RequestParam(name = "token", required = false) String token2) {
+ token = StringUtils.isNotBlank(token) ? token : token2;
+ if (!StringUtils.isNotBlank(token)) {
+ log.info("Token is empty");
+ return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ Boolean result = idpClientManager.isValid(token);
+
+ if (result) {
+ return new ResponseEntity<>(result, HttpStatus.OK);
+ } else {
+ return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
+ }
+
+ }
+
+ /**
+ * Returns the list of available roles on the platform
+ *
+ * @return: A list of Roles
+ */
+
+ @ApiOperation(value = "Return the list of the roles active on the platform", response = Role.class, tags = "")
+ @GetMapping("/role/listRoles")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 500, message = "Internal error")})
+ ResponseEntity> getRoles() {
+ List result = roleInterface.findAll();
+ if (result != null) {
+ return new ResponseEntity>(result, HttpStatus.OK);
+ } else {
+ return new ResponseEntity>(result, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+ }
+
+ User getUserFromJWTToken(String token) {
+ User user = new User();
+
+ String[] chunks = token.split("\\.");
+ Base64.Decoder decoder = Base64.getUrlDecoder();
+ String header = new String(decoder.decode(chunks[0]));
+
+ JSONObject payloadObj = new JSONObject(new String(decoder.decode(chunks[1])));
+
+ UserToken userToken = new UserToken();
+ userToken.setValue(token);
+
+ user.setUsername(payloadObj.getString("username"));
+ user.setName(payloadObj.getString("name"));
+ user.setEmail(payloadObj.getString("email"));
+ user.setSurname(payloadObj.getString("family_name"));
+ user.setSubject(payloadObj.getString("sub"));
+
+ return user;
+
+ }
+
+
+ /**
+ * Check if the token is valid and returns the user's details
+ *
+ * @param: User Token
+ * @return: the user's details if the token is valid, an error otherwise
+ */
+ @ApiOperation(value = "Check if the token is valid and return the user", response = Boolean.class, tags = "")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 403, message = "Token not valid or access forbidden"),
+ @ApiResponse(code = 500, message = "Token is null")})
+ @PostMapping("/user/getUserFromToken")
+ ResponseEntity getUserFromToken(
+ @ApiParam(name = "token", type = "String", value = "The user's ID-Provider token", example = "", required = true)
+ @RequestParam String token
+ ) {
+
+ if (token == null || token == "") {
+ log.info("GetUserFromToken: Token is empty");
+ return new ResponseEntity<>(new LocalUserDTO(), HttpStatus.BAD_REQUEST);
+ }
+
+ Boolean isJWT = checkIsJWTToken(token);
+ User userdto = new User();
+ if (isJWT == false) {
+ userdto = idpClientManager.getUserByToken(token);
+ } else {
+ //è un token JWT
+ userdto = getUserFromJWTToken(token);
+ }
+
+ if (userdto == null) {
+ log.info("User not found on ID-Provider - Token is not valid");
+
+ return new ResponseEntity(new LocalUserDTO(), HttpStatus.FORBIDDEN);
+ }
+ User user = getUserFromSubject(userdto.getUuid());
+ if (user == null) {
+
+ log.info("User not found on local DB");
+ /*@TO-DO
+ * L'utente e' registrato nell'identity provider e quindi dovrei abilitarlo anche localmente, mandandolo pero' nella pagina per
+ * completare la registrazione.
+ */
+
+ LocalUserDTO lUDto = dTOManager.userDTO(userdto);
+ lUDto.setNewUser(true);
+
+ return new ResponseEntity(lUDto, HttpStatus.OK);
+ }
+ user.merge(userdto);
+
+ LocalUserDTO lUserDTO = dTOManager.userDTO(user);
+
+ log.info(lUserDTO);
+
+ return new ResponseEntity(lUserDTO, HttpStatus.OK);
+
+ }
+
+ /**
+ * Check if the token is valid and returns the user's id code
+ *
+ * @param: User Token
+ * @return: the user's details if the token is valid, an error otherwise
+ */
+ @ApiOperation(value = "Check if the token is valid and return the user's id", response = Boolean.class, tags = "")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 403, message = "Token not valid or access forbidden"),
+ @ApiResponse(code = 500, message = "Token is null")})
+ @PostMapping("/user/getUserIdFromToken")
+ ResponseEntity getUserFromIdToken(
+ @ApiParam(name = "Authorization", type = "String", value = "The user's ID-Provider token", example = "", required = true) @RequestHeader(name = "Authorization", required = true) String token) {
+ User result = new User();
+
+ if (token == null || token == "") {
+ log.info("Token is empty");
+ return new ResponseEntity(0, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ User userdto = idpClientManager.getUserByToken(token);
+
+ if (userdto == null) {
+ log.info("User not found on ID-Provider - Token is not valid");
+
+ return new ResponseEntity(0, HttpStatus.FORBIDDEN);
+ }
+ //String subject = encryptionManager.encrypt(userdto.getEmail());
+ User user = getUserFromSubject(userdto.getUuid());
+ if (user == null) {
+ log.info("User not found on local DB");
+
+ return new ResponseEntity(0, HttpStatus.FORBIDDEN);
+ }
+ user.merge(userdto);
+
+ return new ResponseEntity(user.getUserid().intValue(), HttpStatus.OK);
+
+ }
+
+ /**
+ * Update the user's password if the tkoen is valid
+ */
+ @PostMapping("/user/updatepassword")
+ public ResponseEntity updatePassword(
+ @ApiParam(name = "Password", type = "Password", value = "User's new pasword", example = "", required = true)
+ @RequestBody LocalUserDTO userDTO,
+ @RequestHeader(name = "Authorization", required = false) String token) {
+
+ User userdto = idpClientManager.getUserByToken(token);
+
+ if (userdto == null) {
+ log.info("User not found on ID-Provider - Token is not valid");
+ return new ResponseEntity(false, HttpStatus.FORBIDDEN);
+ }
+
+ Boolean result = idpClientManager.updatePassword(token, userDTO.getPassword());
+
+ return new ResponseEntity(result, HttpStatus.OK);
+
+ }
+
+ /**
+ * Update the user's password if the tkoen is valid
+ */
+ @PostMapping("/user/update")
+ public ResponseEntity updateUserInfo(
+ @RequestBody LocalUserDTO userDTO,
+ @RequestHeader(name = "Authorization", required = false) String token) {
+
+ User userdto = idpClientManager.getUserByToken(token);
+
+
+ if (userdto == null) {
+ log.info("User not found on ID-Provider - Token is not valid");
+ return new ResponseEntity(false, HttpStatus.FORBIDDEN);
+ }
+
+ User tmpUser = userInterface.findBySubject(userdto.getUuid());
+
+ if (tmpUser == null) {
+ tmpUser = new User();
+ tmpUser.setSubject(userdto.getUuid());
+ }
+
+ for (CommunityDTO cDto : userDTO.getUsercommunities()) {
+ Community c = communityInterface.findById(cDto.getCommunityid()).get();
+ if (tmpUser.getCommunities() == null || !tmpUser.getCommunities().contains(c)) {
+ UserCommunity uc1 = new UserCommunity();
+ uc1.setCommunity(c);
+ uc1.setUser(tmpUser);
+ uc1.setWallet(cDto.getWallet());
+ uc1.setSubscriptiondate(new Date(System.currentTimeMillis()));
+ uc1.setActive(true);
+ tmpUser.setSingleUsercommunity(uc1);
+ Role tmpRole = roleInterface.getById(new Long(2));
+ UserRole ur = new UserRole();
+ ur.setCommunity(c);
+ ur.setUser(tmpUser);
+ ur.setRole(tmpRole);
+ tmpUser.setSingleUserRole(ur);
+ }
+ }
+ try {
+ tmpUser = userInterface.save(tmpUser);
+ } catch (Exception e) {
+ log.info("Eccezione " + e.getLocalizedMessage());
+ }
+ log.info("user saved, probably... the number of available users is " + userInterface.count());
- }
- if (idpClientManager.isValid(userToken)) {
- log.info("Deleting user with token = {} ", userToken);
- userDel = idpClientManager.getUserByToken(userToken);
- }
- if (userDel != null) {
- Boolean resultIDPRemove = idpClientManager.deleteUser(userDel.getEmail());
+ Boolean result = true;
- if (!resultIDPRemove) {
- log.info("Failed to delete user from ID-Provider");
- return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
- }
+ return new ResponseEntity(result, HttpStatus.OK);
- User user = userInterface.findBySubject(userdto.getUuid());
+ }
- if (user == null) {
- log.info("Failed to delete user from DB because the user does not exist");
- return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
- }
- userInterface.delete(user);
- } else if (isEmail) {
- User user = userInterface.findBySubject(userdto.getUuid());
- if (user == null) {
- log.info("Failed to delete user from DB because the user does not exist");
- return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
- }
- userInterface.delete(user);
- } else {
- log.info("Provided input is not valid or user not present in IDP", userToken);
- return new ResponseEntity(false, HttpStatus.FORBIDDEN);
- }
- return new ResponseEntity(true, HttpStatus.OK);
- }
+ /**
+ * List the devices associated to a user
+ *
+ * @param: User Token
+ * @return: the user's details if the token is valid, an error otherwise
+ */
+ @ApiOperation(value = "List the devices associated to a user", response = Boolean.class, tags = "")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"),
+ @ApiResponse(code = 403, message = "Token not valid or access forbidden"),
+ @ApiResponse(code = 500, message = "Token is null")})
+ @PostMapping("/user/getDevices")
+ ResponseEntity> getDevices(
+ @ApiParam(name = "token", type = "String", value = "The user's ID-Provider token", example = "", required = true) @RequestParam String token) {
- /**
- * Login the user by providing user's details if username and password are
- * correct.
- *
- * @param: Username: the user's username
- * @param: Password: the user's password
- * @return: a full user if both username and password are correct, an empty user
- * if not.
- */
-
- @ApiOperation(value = "Login the user. Returns Http.OK and User object if username and password are valid, Http.Forbidden otherwise", response = User.class, tags = "")
- @PostMapping("/user/login")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 403, message = "Username or password are invalid") })
- ResponseEntity login(
- @ApiParam(name = "username", type = "String", value = "The username", example = "", required = true) @RequestParam String username,
- @ApiParam(name = "password", type = "String", value = "The password", example = "", required = true) @RequestParam String password) {
- if (username == null || username == "" || password == null || password == "") {
- log.info("Username or password are empty");
- return new ResponseEntity(new LocalUserDTO(), HttpStatus.FORBIDDEN);
- }
+ List result = new ArrayList();
- User userdto = idpClientManager.login(username, password);
- if (userdto == null) {
- log.info("Wrong username or password");
- return new ResponseEntity(new LocalUserDTO(), HttpStatus.FORBIDDEN);
- }
-
- log.info("UUID: " + userdto.getSubject());
-
- User user = userInterface.findBySubject(userdto.getSubject());
- if (user == null) {
- log.info("Adding into local DB");
- User tempUser = new User();
- tempUser.setSubject(userdto.getSubject());
- tempUser.merge(userdto);
-
- tempUser = userInterface.save(tempUser);
- LocalUserDTO lUserDTO = dTOManager.userDTO(tempUser);
-
- return new ResponseEntity(lUserDTO, HttpStatus.OK);
- }
- for (Device d : user.getDevices()) {
- log.info(d.getDevicename());
- }
+ if (token == null || token == "") {
+ log.info("Token is empty");
+ return new ResponseEntity>(result, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ User userdto = idpClientManager.getUserByToken(token);
- user.merge(userdto);
-
- LocalUserDTO lUserDTO = dTOManager.userDTO(user);
- log.info(lUserDTO.toString());
-
- return new ResponseEntity<>(lUserDTO, HttpStatus.OK);
- }
+ if (userdto == null) {
+ log.info("User not found on ID-Provider - Token is not valid");
- /**
- * Logout the user using the token
- *
- * @param: User Token
- * @return: True if the user is correctly logged out, false otherwise
- */
- @ApiOperation(value = "Logout the user. Returns Http.OK and User object if username and password are valid, Http.Forbidden otherwise", response = Boolean.class, tags = "")
- @PostMapping("/user/logout")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 500, message = "Logout has failed for unknown causes") })
- ResponseEntity logout(
- @ApiParam(name = "token", type = "String", value = "The user's token", example = "", required = true) @RequestParam String token,
- @RequestHeader(name = "Authorization", required = false) String tokenAuth) {
- if (token == null || token == "") {
- if (tokenAuth == null || tokenAuth == "") {
- log.info("Token is empty");
- return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
- } else
- token = tokenAuth;
- }
- Boolean result = idpClientManager.logout(token);
+ return new ResponseEntity>(result, HttpStatus.FORBIDDEN);
+ }
+ //String subject = encryptionManager.encrypt(userdto.getEmail());
+ User user = getUserFromSubject(userdto.getUuid());
+ if (user == null) {
+ log.info("User not found on local DB");
- if (result) {
- return new ResponseEntity(result, HttpStatus.OK);
- } else {
- log.info("Failed to logout");
- return new ResponseEntity(result, HttpStatus.INTERNAL_SERVER_ERROR);
- }
+ return new ResponseEntity>(result, HttpStatus.FORBIDDEN);
+ }
- }
+ try {
+ result = userInterface.findAllDevicesByUserid(user.getUserid());
- /**
- * Check if the token is valid and alive
- *
- * @param: User Token
- * @return: True if the user is the token is valid, false otherwise
- */
- @ApiOperation(value = "Check if the token is valid and return a boolean", response = Boolean.class, tags = "")
- @PostMapping("/user/isTokenValid")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 403, message = "Token not valid"),
- @ApiResponse(code = 500, message = "Token is null") })
- ResponseEntity checkToken(
- @RequestHeader(name = "Authorization", required = false) String token,
- @ApiParam(name = "token", type = "String", value = "The user's token", example = "", required = false)
- @RequestParam (name = "token", required = false) String token2 ) {
- token = StringUtils.hasText(token) ? token : token2;
- if (!StringUtils.hasText(token)) {
- log.info("Token is empty");
- return new ResponseEntity(false, HttpStatus.INTERNAL_SERVER_ERROR);
- }
- Boolean result = idpClientManager.isValid(token);
+ } catch (Exception e) {
+ System.out.println(e.getLocalizedMessage());
+ }
+ return new ResponseEntity>(result, HttpStatus.OK);
- if (result) {
- return new ResponseEntity(result, HttpStatus.OK);
- } else {
- return new ResponseEntity(result, HttpStatus.FORBIDDEN);
- }
+ }
- }
+ public User persistNewUser(User u, Community c, Role r) {
- /**
- * Returns the list of available roles on the platform
- *
- * @return: A list of Roles
- */
-
- @ApiOperation(value = "Return the list of the roles active on the platform", response = Role.class, tags = "")
- @GetMapping("/role/listRoles")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 500, message = "Internal error") })
- ResponseEntity> getRoles() {
- List result = roleInterface.findAll();
- if (result != null) {
- return new ResponseEntity>(result, HttpStatus.OK);
- } else {
- return new ResponseEntity>(result, HttpStatus.INTERNAL_SERVER_ERROR);
- }
+ UserCommunity uc = new UserCommunity();
+ uc.setCommunity(c);
+ uc.setUser(u);
- }
-
- User getUserFromJWTToken(String token) {
- User user = new User();
-
- String[] chunks = token.split("\\.");
- Base64.Decoder decoder = Base64.getUrlDecoder();
- String header = new String(decoder.decode(chunks[0]));
-
- JSONObject payloadObj = new JSONObject(new String(decoder.decode(chunks[1])));
-
- UserToken userToken = new UserToken();
- userToken.setValue(token);
-
- user.setUsername(payloadObj.getString("username"));
- user.setName(payloadObj.getString("name"));
- user.setEmail(payloadObj.getString("email"));
- user.setSurname(payloadObj.getString("family_name"));
- user.setSubject(payloadObj.getString("sub"));
-
- return user;
-
- }
+ u.setSingleUsercommunity(uc);
+ UserRole ur = new UserRole();
- /**
- * Check if the token is valid and returns the user's details
- *
- * @param: User Token
- * @return: the user's details if the token is valid, an error otherwise
- */
- @ApiOperation(value = "Check if the token is valid and return the user", response = Boolean.class, tags = "")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 403, message = "Token not valid or access forbidden"),
- @ApiResponse(code = 500, message = "Token is null") })
- @PostMapping("/user/getUserFromToken")
- ResponseEntity getUserFromToken(
- @ApiParam(name = "token", type = "String", value = "The user's ID-Provider token", example = "", required = true)
- @RequestParam String token
- ) {
-
- if (token == null || token == "") {
- log.info("GetUserFromToken: Token is empty");
- return new ResponseEntity<>(new LocalUserDTO(), HttpStatus.BAD_REQUEST);
- }
-
- Boolean isJWT = checkIsJWTToken(token);
- User userdto = new User();
- if (isJWT == false) {
- userdto = idpClientManager.getUserByToken(token);}
- else {
- //è un token JWT
- userdto = getUserFromJWTToken(token);
- }
+ ur.setRole(r);
+ ur.setCommunity(c);
+ ur.setUser(u);
+ u.addUserRole(ur);
- if (userdto == null) {
- log.info("User not found on ID-Provider - Token is not valid");
+ userInterface.save(u);
- return new ResponseEntity(new LocalUserDTO(), HttpStatus.FORBIDDEN);
- }
- User user = getUserFromSubject(userdto.getUuid());
- if (user == null) {
-
- log.info("User not found on local DB");
- /*@TO-DO
- * L'utente e' registrato nell'identity provider e quindi dovrei abilitarlo anche localmente, mandandolo pero' nella pagina per
- * completare la registrazione.
- */
-
- LocalUserDTO lUDto = dTOManager.userDTO(userdto);
- lUDto.setNewUser(true);
-
- return new ResponseEntity(lUDto, HttpStatus.OK);
- }
- user.merge(userdto);
+ return u;
- LocalUserDTO lUserDTO = dTOManager.userDTO(user);
+ }
- log.info(lUserDTO);
+ private User persistNewUserWithCommunityIdAndRoleId(User u, Long cId, Long rId) {
- return new ResponseEntity(lUserDTO, HttpStatus.OK);
+ Community c = communityInterface.findById(cId).get();
- }
+ Role r = roleInterface.findById(rId).get();
- /**
- * Check if the token is valid and returns the user's id code
- *
- * @param: User Token
- * @return: the user's details if the token is valid, an error otherwise
- */
- @ApiOperation(value = "Check if the token is valid and return the user's id", response = Boolean.class, tags = "")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 403, message = "Token not valid or access forbidden"),
- @ApiResponse(code = 500, message = "Token is null") })
- @PostMapping("/user/getUserIdFromToken")
- ResponseEntity getUserFromIdToken(
- @ApiParam(name = "Authorization", type = "String", value = "The user's ID-Provider token", example = "", required = true) @RequestHeader(name = "Authorization", required = true) String token) {
- User result = new User();
-
- if (token == null || token == "") {
- log.info("Token is empty");
- return new ResponseEntity(0, HttpStatus.INTERNAL_SERVER_ERROR);
- }
- User userdto = idpClientManager.getUserByToken(token);
+ return persistNewUser(u, c, r);
- if (userdto == null) {
- log.info("User not found on ID-Provider - Token is not valid");
+ }
- return new ResponseEntity(0, HttpStatus.FORBIDDEN);
- }
- //String subject = encryptionManager.encrypt(userdto.getEmail());
- User user = getUserFromSubject(userdto.getUuid());
- if (user == null) {
- log.info("User not found on local DB");
+ private User persistNewUserWithCommunityNameAndRoleName(User u, String cName, String rName) {
+ Community c = communityInterface.findByCommunityName(cName);
- return new ResponseEntity(0, HttpStatus.FORBIDDEN);
- }
- user.merge (userdto);
-
- return new ResponseEntity(user.getUserid().intValue(), HttpStatus.OK);
-
- }
- /**
- * Update the user's password if the tkoen is valid
- *
- */
- @PostMapping("/user/updatepassword")
- public ResponseEntity updatePassword(
- @ApiParam(name = "Password", type = "Password", value = "User's new pasword", example = "", required = true)
- @RequestBody LocalUserDTO userDTO,
- @RequestHeader(name = "Authorization", required = false) String token) {
-
- User userdto = idpClientManager.getUserByToken(token);
-
- if (userdto == null) {
- log.info("User not found on ID-Provider - Token is not valid");
- return new ResponseEntity(false, HttpStatus.FORBIDDEN);
- }
-
- Boolean result = idpClientManager.updatePassword(token, userDTO.getPassword());
-
- return new ResponseEntity(result, HttpStatus.OK);
-
- }
-
- /**
- * Update the user's password if the tkoen is valid
- *
- */
- @PostMapping("/user/update")
- public ResponseEntity updateUserInfo(
- @RequestBody LocalUserDTO userDTO,
- @RequestHeader(name = "Authorization", required = false) String token) {
-
- User userdto = idpClientManager.getUserByToken(token);
-
-
- if (userdto == null) {
- log.info("User not found on ID-Provider - Token is not valid");
- return new ResponseEntity(false, HttpStatus.FORBIDDEN);
- }
-
- User tmpUser = userInterface.findBySubject(userdto.getUuid());
-
- if (tmpUser == null) {
- tmpUser = new User();
- tmpUser.setSubject(userdto.getUuid());
- }
-
- for (CommunityDTO cDto : userDTO.getUsercommunities()) {
- Community c = communityInterface.findByCommunityid(cDto.getCommunityid());
- if (tmpUser.getCommunities() == null || !tmpUser.getCommunities().contains(c)) {
- UserCommunity uc1 = new UserCommunity();
- uc1.setCommunity(c);
- uc1.setUser(tmpUser);
- uc1.setWallet(cDto.getWallet());
- uc1.setSubscriptiondate(new Date(System.currentTimeMillis()));
- uc1.setActive(true);
- tmpUser.setSingleUsercommunity(uc1);
- Role tmpRole = roleInterface.getById(new Long(2));
- UserRole ur = new UserRole();
- ur.setCommunity(c);
- ur.setUser(tmpUser);
- ur.setRole(tmpRole);
- tmpUser.setSingleUserRole(ur);
- }
- }
- try {
- tmpUser = userInterface.save(tmpUser);
- }catch (Exception e) {
- log.info("Eccezione " + e.getLocalizedMessage());
- }
- log.info("user saved, probably... the number of available users is " + userInterface.count());
-
- Boolean result = true;
-
- return new ResponseEntity(result, HttpStatus.OK);
-
- }
-
-
- /**
- * List the devices associated to a user
- *
- * @param: User Token
- * @return: the user's details if the token is valid, an error otherwise
- */
- @ApiOperation(value = "List the devices associated to a user", response = Boolean.class, tags = "")
- @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
- @ApiResponse(code = 403, message = "Token not valid or access forbidden"),
- @ApiResponse(code = 500, message = "Token is null") })
- @PostMapping("/user/getDevices")
- ResponseEntity> getDevices(
- @ApiParam(name = "token", type = "String", value = "The user's ID-Provider token", example = "", required = true) @RequestParam String token) {
-
- List result = new ArrayList();
-
- if (token == null || token == "") {
- log.info("Token is empty");
- return new ResponseEntity>(result, HttpStatus.INTERNAL_SERVER_ERROR);
- }
- User userdto = idpClientManager.getUserByToken(token);
-
- if (userdto == null) {
- log.info("User not found on ID-Provider - Token is not valid");
+ Role r = roleInterface.findByRolename(rName);
- return new ResponseEntity>(result, HttpStatus.FORBIDDEN);
- }
- //String subject = encryptionManager.encrypt(userdto.getEmail());
- User user = getUserFromSubject(userdto.getUuid());
- if (user == null) {
- log.info("User not found on local DB");
-
- return new ResponseEntity>(result, HttpStatus.FORBIDDEN);
- }
-
- try {
- result = userInterface.findAllDevicesByUserid(user.getUserid());
+ return persistNewUser(u, c, r);
- } catch (Exception e) {
- System.out.println(e.getLocalizedMessage());
- }
- return new ResponseEntity>(result, HttpStatus.OK);
-
- }
-
- public User persistNewUser(User u, Community c, Role r) {
-
- UserCommunity uc = new UserCommunity();
- uc.setCommunity(c);
- uc.setUser(u);
-
- u.setSingleUsercommunity(uc);
-
- UserRole ur = new UserRole();
-
- ur.setRole(r);
- ur.setCommunity(c);
- ur.setUser(u);
- u.addUserRole(ur);
-
- userInterface.save(u);
-
- return u;
-
- }
-
- private User persistNewUserWithCommunityIdAndRoleId(User u, Long cId, Long rId) {
-
- Community c = communityInterface.findByCommunityid(cId);
-
- Role r = roleInterface.findById(rId).get();
-
- return persistNewUser(u, c, r);
-
- }
-
- private User persistNewUserWithCommunityNameAndRoleName(User u, String cName, String rName) {
- Community c = communityInterface.findByCommunityName(cName);
-
- Role r = roleInterface.findByRolename(rName);
-
- return persistNewUser(u, c, r);
-
- }
+ }
//
// private void deleteUserBySubject(String subject) {
// User newUser;
@@ -1278,52 +1260,51 @@ public class UserController {
//
// }
- public User getUserFromSubject(String subject) {
- User user = new User();
- try {
- user = userInterface.findBySubject(subject);
+ public User getUserFromSubject(String subject) {
+ User user = new User();
+ try {
+ user = userInterface.findBySubject(subject);
+
+ } catch (Exception e) {
+ log.info(e.getLocalizedMessage());
+ return user;
+
+ }
+ return user;
+ }
+
+ @Getter
+ @Setter
+ @AllArgsConstructor
+ @NoArgsConstructor
+ private class ResultMessage {
+ private Boolean success;
+ private String message;
+
+ }
+
+ public User getLocalUserFromToken(String token) {
+ User user = new User();
+ Boolean isValid = idpClientManager.isValid(token);
+
+ if (isValid) {
+ User userdto = idpClientManager.getUserByToken(token);
+
+ user = userInterface.findBySubject(userdto.getUuid());
+ }
+ return user;
+ }
+
+ private Boolean checkIsJWTToken(String token) {
+
+ String[] chunks = token.split("\\.");
+ Base64.Decoder decoder = Base64.getUrlDecoder();
+
+ String header = new String(decoder.decode(chunks[0]));
+ if (header.contains("JWT")) return true;
+
+ return false;
+ }
- } catch (Exception e) {
- log.info(e.getLocalizedMessage());
- return user;
- }
- return user;
- }
-
- @Getter
- @Setter
- @AllArgsConstructor
- @NoArgsConstructor
- private class ResultMessage{
- private Boolean success;
- private String message;
-
- }
-
- public User getLocalUserFromToken(String token) {
- User user = new User();
- Boolean isValid = idpClientManager.isValid(token);
-
- if (isValid) {
- User userdto = idpClientManager.getUserByToken(token);
-
- user = userInterface.findBySubject(userdto.getUuid());
- }
- return user;
- }
-
- private Boolean checkIsJWTToken(String token) {
-
- String[] chunks = token.split("\\.");
- Base64.Decoder decoder = Base64.getUrlDecoder();
-
- String header = new String(decoder.decode(chunks[0]));
- if (header.contains("JWT")) return true;
-
- return false;
- }
-
-
-
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/structure/ColumnCommentDTO.java b/gecoregistration/src/main/java/it/enea/cruise/dto/ColumnCommentDTO.java
similarity index 95%
rename from gecoregistration/src/main/java/it/enea/cruise/model/structure/ColumnCommentDTO.java
rename to gecoregistration/src/main/java/it/enea/cruise/dto/ColumnCommentDTO.java
index 0a4ce5e5daa50907aff4a63f43822eeb1cf5d981..9c584fdd660052ad39da06d9dd949cb2049206fe 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/structure/ColumnCommentDTO.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/dto/ColumnCommentDTO.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.model.structure;
+package it.enea.cruise.dto;
import java.util.HashMap;
import java.util.List;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/structure/DescriptionDTO.java b/gecoregistration/src/main/java/it/enea/cruise/dto/DescriptionDTO.java
similarity index 84%
rename from gecoregistration/src/main/java/it/enea/cruise/model/structure/DescriptionDTO.java
rename to gecoregistration/src/main/java/it/enea/cruise/dto/DescriptionDTO.java
index def57f49629dbb2d0760503614f8d45ed00933c9..27d9d46e250919dcabbd75082a8b404ea3791708 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/structure/DescriptionDTO.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/dto/DescriptionDTO.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.model.structure;
+package it.enea.cruise.dto;
import lombok.Getter;
import lombok.Setter;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/dto/LocalUserDTO.java b/gecoregistration/src/main/java/it/enea/cruise/dto/LocalUserDTO.java
index e27a748d9bd9881cac2175a1fbbce1649e7954e3..b8f307e13e0d212f51fda8983f66014d0c858496 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/dto/LocalUserDTO.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/dto/LocalUserDTO.java
@@ -4,7 +4,6 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
-import it.enea.cruise.model.user.UserToken;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/structure/TableCommentDTO.java b/gecoregistration/src/main/java/it/enea/cruise/dto/TableCommentDTO.java
similarity index 94%
rename from gecoregistration/src/main/java/it/enea/cruise/model/structure/TableCommentDTO.java
rename to gecoregistration/src/main/java/it/enea/cruise/dto/TableCommentDTO.java
index ff3fedbf2637de7c88df67c42b2bb70e098ddf07..62b4e34c6a1c4c201bc3dfdf3f36ef47d9f93742 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/structure/TableCommentDTO.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/dto/TableCommentDTO.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.model.structure;
+package it.enea.cruise.dto;
import java.util.HashMap;
import java.util.List;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserToken.java b/gecoregistration/src/main/java/it/enea/cruise/dto/UserToken.java
similarity index 81%
rename from gecoregistration/src/main/java/it/enea/cruise/model/user/UserToken.java
rename to gecoregistration/src/main/java/it/enea/cruise/dto/UserToken.java
index 18a29be906c3e9b02d25f8f20e196e273b32a90d..9502bc2e256bb26c17354103559d72fd10bafc34 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserToken.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/dto/UserToken.java
@@ -1,14 +1,15 @@
-package it.enea.cruise.model.user;
+package it.enea.cruise.dto;
import java.util.Date;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import lombok.*;
@Getter
@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
@ToString()
public class UserToken {
@@ -16,8 +17,6 @@ public class UserToken {
private Date expiration;
private String value;
- public UserToken() {}
-
// public Date getCreation() {
// return creation;
// }
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/Cluster.java b/gecoregistration/src/main/java/it/enea/cruise/model/Cluster.java
index 71b53b977474f7b825cd70d97853dff89c9eff66..15fb3f11e084e54d93b3fbb75e53d70f92a3f84e 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/Cluster.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/Cluster.java
@@ -10,10 +10,10 @@ import lombok.Getter;
import lombok.Setter;
@Entity
-@Table (name = "Cluster")
+@Table (name = "clusters")
@Getter
@Setter
-public class Cluster implements Serializable{
+public class Cluster implements Serializable {
@Id
private Integer clusterid;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/ClusterGroup.java b/gecoregistration/src/main/java/it/enea/cruise/model/ClusterGroup.java
index c32d7a4cbcb81a4eb0d4e92532a65ff367fa7992..c0918ab56c18ec37c26b6bfd0b00d171238b014f 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/ClusterGroup.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/ClusterGroup.java
@@ -9,9 +9,9 @@ import lombok.Getter;
import lombok.Setter;
@Entity
-@Table (name = "clustergroups")
@Getter
@Setter
+@Table (name = "clustergroups")
public class ClusterGroup {
@Id
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/Flow.java b/gecoregistration/src/main/java/it/enea/cruise/model/Flow.java
deleted file mode 100644
index 2f93b68ce4349534b029911a76b216793cbe7cfb..0000000000000000000000000000000000000000
--- a/gecoregistration/src/main/java/it/enea/cruise/model/Flow.java
+++ /dev/null
@@ -1,231 +0,0 @@
-package it.enea.cruise.model;
-
-import java.io.Serializable;
-import javax.persistence.*;
-
-
-/**
- * The persistent class for the flows database table.
- *
- */
-@Entity
-@Table(name="flows")
-@NamedQuery(name="Flow.findAll", query="SELECT f FROM Flow f")
-public class Flow implements Serializable {
- private static final long serialVersionUID = 1L;
-
- @Id
- private Integer flowid;
-
- private String channeldescription;
-
- private String cronfrequence;
-
- private String dataformatreference;
-
- private Integer datasyntax;
-
- private String description;
-
- private String endtime;
-
- private String flowname;
-
- private Integer frequence;
-
- private Integer frequencederogation;
-
- private Integer gdprclassification;
-
- private String measurecronfrequence;
-
- private Integer measurefrequence;
-
- private Integer measurefrequencederogation;
-
- private Integer measurementtable;
-
- private Integer measurementtype;
-
- private String note;
-
- private String onerrordo;
-
- private String starttime;
-
- private Integer supplierid;
-
- private String userightsstatement;
-
- public Flow() {
- }
-
- public Integer getFlowid() {
- return this.flowid;
- }
-
- public void setFlowid(Integer flowid) {
- this.flowid = flowid;
- }
-
- public String getChanneldescription() {
- return this.channeldescription;
- }
-
- public void setChanneldescription(String channeldescription) {
- this.channeldescription = channeldescription;
- }
-
- public String getCronfrequence() {
- return this.cronfrequence;
- }
-
- public void setCronfrequence(String cronfrequence) {
- this.cronfrequence = cronfrequence;
- }
-
- public String getDataformatreference() {
- return this.dataformatreference;
- }
-
- public void setDataformatreference(String dataformatreference) {
- this.dataformatreference = dataformatreference;
- }
-
- public Integer getDatasyntax() {
- return this.datasyntax;
- }
-
- public void setDatasyntax(Integer datasyntax) {
- this.datasyntax = datasyntax;
- }
-
- public String getDescription() {
- return this.description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getEndtime() {
- return this.endtime;
- }
-
- public void setEndtime(String endtime) {
- this.endtime = endtime;
- }
-
- public String getFlowname() {
- return this.flowname;
- }
-
- public void setFlowname(String flowname) {
- this.flowname = flowname;
- }
-
- public Integer getFrequence() {
- return this.frequence;
- }
-
- public void setFrequence(Integer frequence) {
- this.frequence = frequence;
- }
-
- public Integer getFrequencederogation() {
- return this.frequencederogation;
- }
-
- public void setFrequencederogation(Integer frequencederogation) {
- this.frequencederogation = frequencederogation;
- }
-
- public Integer getGdprclassification() {
- return this.gdprclassification;
- }
-
- public void setGdprclassification(Integer gdprclassification) {
- this.gdprclassification = gdprclassification;
- }
-
- public String getMeasurecronfrequence() {
- return this.measurecronfrequence;
- }
-
- public void setMeasurecronfrequence(String measurecronfrequence) {
- this.measurecronfrequence = measurecronfrequence;
- }
-
- public Integer getMeasurefrequence() {
- return this.measurefrequence;
- }
-
- public void setMeasurefrequence(Integer measurefrequence) {
- this.measurefrequence = measurefrequence;
- }
-
- public Integer getMeasurefrequencederogation() {
- return this.measurefrequencederogation;
- }
-
- public void setMeasurefrequencederogation(Integer measurefrequencederogation) {
- this.measurefrequencederogation = measurefrequencederogation;
- }
-
- public Integer getMeasurementtable() {
- return this.measurementtable;
- }
-
- public void setMeasurementtable(Integer measurementtable) {
- this.measurementtable = measurementtable;
- }
-
- public Integer getMeasurementtype() {
- return this.measurementtype;
- }
-
- public void setMeasurementtype(Integer measurementtype) {
- this.measurementtype = measurementtype;
- }
-
- public String getNote() {
- return this.note;
- }
-
- public void setNote(String note) {
- this.note = note;
- }
-
- public String getOnerrordo() {
- return this.onerrordo;
- }
-
- public void setOnerrordo(String onerrordo) {
- this.onerrordo = onerrordo;
- }
-
- public String getStarttime() {
- return this.starttime;
- }
-
- public void setStarttime(String starttime) {
- this.starttime = starttime;
- }
-
- public Integer getSupplierid() {
- return this.supplierid;
- }
-
- public void setSupplierid(Integer supplierid) {
- this.supplierid = supplierid;
- }
-
- public String getUserightsstatement() {
- return this.userightsstatement;
- }
-
- public void setUserightsstatement(String userightsstatement) {
- this.userightsstatement = userightsstatement;
- }
-
-}
\ No newline at end of file
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/data/DataConsumption.java b/gecoregistration/src/main/java/it/enea/cruise/model/data/DataConsumption.java
index de0541aaa354a3b44663f02a28a772afcba5c699..bfa130eabd53ecc58b2d09545b1fcbcb9cb87454 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/data/DataConsumption.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/data/DataConsumption.java
@@ -12,11 +12,11 @@ import lombok.Getter;
import lombok.Setter;
-@Entity(name = "dataConsumption")
-@Table(name = "vw_counterreadingusers")
-@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
+@Entity
+@Table(name = "vw_counterreadingusers")
+@JsonInclude(JsonInclude.Include.NON_NULL)
public class DataConsumption {
@Id
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/AdmittedQueryValues.java b/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/AdmittedQueryValues.java
deleted file mode 100644
index 42826fb51c8c0ea05d8eb5750a1634961fcdb0a0..0000000000000000000000000000000000000000
--- a/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/AdmittedQueryValues.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package it.enea.cruise.model.parametricQuery;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.Transient;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@Entity (name = "admittedqueryvalues")
-@Table(name = "cruise.t_admittedqueryvalues")
-@Getter
-@Setter
-public class AdmittedQueryValues {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int admittedqueryvalueid;
-
- private String type;
-
- private String value;
-
- @Transient
- private List queries;
-
- @Transient
- private Map> listOfValue;
-
- public int getId() {
- return admittedqueryvalueid;
- }
-
- public void setId(int admittedqueryvalueid) {
- this.admittedqueryvalueid = admittedqueryvalueid;
- }
-
-}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/ParametricQuery.java b/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/ParametricQuery.java
deleted file mode 100644
index 22f480ad59928a609294929c12655ea6af226115..0000000000000000000000000000000000000000
--- a/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/ParametricQuery.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package it.enea.cruise.model.parametricQuery;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinTable;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToMany;
-import javax.persistence.PostLoad;
-import javax.persistence.Table;
-import javax.persistence.Transient;
-
-import org.hibernate.annotations.FetchMode;
-import org.hibernate.annotations.Fetch;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import lombok.Getter;
-import lombok.Setter;
-
-
-@Entity (name = "parametricquery")
-@Table (name = "cruise.parametricquery")
-@Getter
-@Setter
-@JsonInclude(JsonInclude.Include.NON_NULL)
-public class ParametricQuery {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long queryid;
- private String name;
- //@JsonIgnore
- private String sql;
- private String description;
- private String queryType; // {SQL, API};
-
- @Transient
- @JsonProperty("metadata")
- @JsonInclude(JsonInclude.Include.NON_NULL)
- List> parameterMetadata;
-
- @ManyToMany
- @JoinTable(
- name = "cruise.queries_parameters",
- joinColumns = @JoinColumn
- (name = "queryid"),
- inverseJoinColumns = @JoinColumn(name = "paramid"))
- @Fetch(FetchMode.JOIN)
- //@JsonManagedReference(value = "parametricquery-parameter")
- @JsonProperty("parameters")
- @JsonIgnoreProperties("parametricquery")
- private List parameters;
-
- @ManyToMany
- @JoinTable(
- name = "cruise.queries_admittedqueryvalues",
- joinColumns = @JoinColumn (name = "queryid"),
- inverseJoinColumns = @JoinColumn(name = "admittedqueryvalueid"))
- private List admittedqueryvalues;
-
- @Transient
- Map> values = new HashMap>();
-
- @PostLoad
- public void postLoad(){
-
-
- for(AdmittedQueryValues aqv : admittedqueryvalues) {
- List tempList;
- if (values.containsKey(aqv.getType())) {
- tempList = values.get(aqv.getType());
- tempList.add(aqv.getValue());
-
- }else {
- tempList = new ArrayList();
- tempList.add(aqv.getValue());
- }
- values.put(aqv.getType(), tempList);
- }
- }
-
-// public String getName() {
-// return name;
-// }
-// public void setName(String name) {
-// this.name = name;
-// }
-// public String getSql() {
-// return sql;
-// }
-// public void setSql(String sQL) {
-// sql = sQL;
-// }
-// public List getParameters() {
-// return parameters;
-// }
-// public void setParameters(List parameters) {
-// this.parameters = parameters;
-// }
-// public Long getQueryid() {
-// return queryid;
-// }
-// public void setQueryid(Long queryid) {
-// this.queryid = queryid;
-// }
-// public String getDescription() {
-// return description;
-// }
-// public void setDescription(String description) {
-// this.description = description;
-// }
-// public String getQueryType() {
-// return queryType;
-// }
-// public void setQueryType(String queryType) {
-// this.queryType = queryType;
-// }
-//
-// public void setAdmittedqueryvalues(List admittedqueryvalues) {
-// this.admittedqueryvalues = admittedqueryvalues;
-// }
-//
-// public void setValues(Map> values) {
-// this.values = values;
-// }
-//
-// public Map> getValues() {
-// return values;
-// }
-//
-// public List> getParameterMetadata() {
-// return parameterMetadata;
-// }
-//
-// public void setParameterMetadata(List> parameterMetadata) {
-// this.parameterMetadata = parameterMetadata;
-// }
-
-
-
-}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/structure/ForeignKey.java b/gecoregistration/src/main/java/it/enea/cruise/model/structure/ForeignKey.java
index 7d721b005b37c626038c6a7ea9e32ca7b6353c92..f55be36734a6ab305a11215a8b5b658b6cd50e31 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/structure/ForeignKey.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/structure/ForeignKey.java
@@ -13,12 +13,12 @@ import lombok.Setter;
import lombok.ToString;
@Entity
-@Table(name="vw_foreignkey", schema="cruise")
@Immutable
@Getter
@Setter
-@NoArgsConstructor
@ToString
+@NoArgsConstructor
+@Table(name="vw_foreignkey", schema="cruise")
public class ForeignKey {
@Id
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/structure/VwTableMetadata.java b/gecoregistration/src/main/java/it/enea/cruise/model/structure/VwTableMetadata.java
index ba35487010d24d7dd693dcec535d3f103e700ca3..6973983a5a57cae49b7421b99ddca72209fed749 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/structure/VwTableMetadata.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/structure/VwTableMetadata.java
@@ -16,12 +16,12 @@ import lombok.ToString;
*
*/
@Entity
-@Table(name="vw_table_metadata", schema="cruise")
-@Immutable
@Getter
@Setter
-@NoArgsConstructor
@ToString
+@Immutable
+@NoArgsConstructor
+@Table(name="vw_table_metadata", schema="cruise")
public class VwTableMetadata implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/AdmittedQueryValues.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/AdmittedQueryValues.java
new file mode 100644
index 0000000000000000000000000000000000000000..184396956322882f72df3cb3a284ed9e4910e681
--- /dev/null
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/AdmittedQueryValues.java
@@ -0,0 +1,31 @@
+package it.enea.cruise.model.user;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.*;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Entity
+@Getter
+@Setter
+@Table(name = "t_admittedqueryvalues", schema = "cruise")
+public class AdmittedQueryValues {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @Column(name = "admittedqueryvalueid")
+ private Long id;
+
+ private String type;
+
+ private String value;
+
+ @Transient
+ private List queries;
+
+ @Transient
+ private Map> listOfValue;
+}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/Community.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/Community.java
index f3923e1c518e4d82b4f80e93a80ebe2dd7c32b9e..1842fda8dcd43f65d7da4654bb07bd9f05537116 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/Community.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/Community.java
@@ -1,29 +1,18 @@
package it.enea.cruise.model.user;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-
-import org.hibernate.annotations.Fetch;
-import org.hibernate.annotations.FetchMode;
-
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
import lombok.Getter;
import lombok.Setter;
+import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.FetchMode;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
/**
*
@@ -34,15 +23,14 @@ import lombok.Setter;
*
*/
-@Entity(name = "community")
-@Table(name = "communities")
+@Entity
@Getter
@Setter
+@Table(name = "communities")
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "communityid",
scope = User.class)
-@NamedQuery(name = "Community.findAllOnlyNameandid", query = "select c.communityid as id, c.communityName as name, c.description as desc from community c")
public class Community {
/*
* Properties of the Community
@@ -51,7 +39,7 @@ public class Community {
@Id
@GeneratedValue
@Column(name = "communityid")
- private Long communityid;
+ private Long id;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Column(name = "communityname")
@@ -84,7 +72,7 @@ public class Community {
}
public Community(Long id, String name, String description) {
- this.communityid = id;
+ this.id = id;
this.communityName = name;
this.description = description;
}
@@ -103,41 +91,4 @@ public class Community {
public int hashCode() {
return Objects.hash(communityName);
}
-
- /*
- * Getters and Setters
- */
-
-// public Long getCommunityid() {
-// return communityid;
-// }
-//
-// public void setCommunityid(Long communityid) {
-// this.communityid = communityid;
-// }
-//
-// public String getCommunityName() {
-// return communityName;
-// }
-//
-// public void setCommunityName(String communityName) {
-// this.communityName = communityName;
-// }
-//
-// public List getUserCommunities() {
-// return userCommunities;
-// }
-//
-// public void setUserCommunities(List userCommunities) {
-// this.userCommunities = userCommunities;
-// }
-//
-// public String getDescription() {
-// return description;
-// }
-//
-// public void setDescription(String description) {
-// this.description = description;
-// }
-
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/Device.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/Device.java
index 8e29a764cc4a34c7ce59bda7e4c273637d9e62b9..0470e771accb2251c7b11f817561f9e3cac9f4db 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/Device.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/Device.java
@@ -1,36 +1,29 @@
package it.enea.cruise.model.user;
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.MapsId;
-import javax.persistence.Table;
-
-import org.springframework.stereotype.Component;
-
import com.fasterxml.jackson.annotation.JsonInclude;
-
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
+import org.springframework.stereotype.Component;
-@Entity (name="device")
-@Table (name= "devices")
-@JsonInclude(JsonInclude.Include.NON_NULL)
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+@Entity
@Getter
@Setter
-@NoArgsConstructor
@ToString
@Component
+@NoArgsConstructor
+@Table(name= "devices")
+@JsonInclude(JsonInclude.Include.NON_NULL)
public class Device implements Serializable {
@Id
- private String deviceid;
+ @Column(name = "deviceid")
+ private String id;
private int supplierid;
@@ -68,5 +61,4 @@ public class Device implements Serializable {
private String activationdate;
private Date deactivationdate;
-
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/Flow.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/Flow.java
index 21f15a34b6cd05e55b57c12b30e215ab5fd76f61..850dfbe53e92cdfdd5da55c181f9b97897c146d5 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/Flow.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/Flow.java
@@ -15,17 +15,18 @@ import lombok.ToString;
* The persistent class for the flows database table.
*
*/
-@Entity (name="flow")
-@Table(name="flows")
+@Entity
@Getter
@Setter
-@NoArgsConstructor
@ToString
+@NoArgsConstructor
+@Table(name="flows")
public class Flow implements Serializable {
private static final long serialVersionUID = 1L;
@Id
- private Integer flowid;
+ @Column(name = "flowid")
+ private Integer id;
private String channeldescription;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunity.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunity.java
index 42cf1fbce612da702a3aac86e8c1606aa1e19e50..92e6440b49b7c075a05f169e8cb3d7b0b2194465 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunity.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunity.java
@@ -1,21 +1,13 @@
package it.enea.cruise.model.user;
-import javax.persistence.Column;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.MapsId;
-import javax.persistence.Table;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
+import javax.persistence.*;
+
-@Entity(name = "flowCommunity")
+@Entity
@Table(name = "flows_communities")
public class FlowCommunity {
-
-
@EmbeddedId
@JsonIgnore
private FlowCommunityId id = new FlowCommunityId();
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunityId.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunityId.java
index 14a835f306e4a05186fb2d16ed162cf1bbe8694e..1229cbdc3d9da3be6ce74b714a43a063d030669a 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunityId.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/FlowCommunityId.java
@@ -1,22 +1,19 @@
package it.enea.cruise.model.user;
-import java.io.Serializable;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
-
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
+import java.io.Serializable;
@Getter
@Setter
-@NoArgsConstructor
@Embeddable
-public class FlowCommunityId implements Serializable{
-
-
+@NoArgsConstructor
+public class FlowCommunityId implements Serializable {
@Transient
private static final long serialVersionUID = 1L;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/LocalQueryParameter.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/LocalQueryParameter.java
similarity index 74%
rename from gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/LocalQueryParameter.java
rename to gecoregistration/src/main/java/it/enea/cruise/model/user/LocalQueryParameter.java
index b3c63fc57f84f3fc118a7181bf83973185833c9b..408dea0889b9de3296da88514f5ff987f104e549 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/parametricQuery/LocalQueryParameter.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/LocalQueryParameter.java
@@ -1,33 +1,21 @@
-package it.enea.cruise.model.parametricQuery;
+package it.enea.cruise.model.user;
-import java.util.List;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-
-//import org.codehaus.jackson.annotate.JsonBackReference;
-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import javax.persistence.*;
+import java.util.List;
+
-@Entity (name = "localqueryparameter")
-@Table (name= "cruise.localqueryparameters")
+@Entity
+@Table (name= "localqueryparameters", schema = "cruise")
public class LocalQueryParameter {
@Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="localqueryparameterid")
private Long paramId;
-
- //@JsonIgnore
- //private Long queryid;
-
+
private String description;
private String name;
@@ -55,14 +43,6 @@ public class LocalQueryParameter {
this.paramId = paramId;
}
-// public Long getQueryid() {
-// return queryid;
-// }
-//
-// public void setQueryid(Long queryid) {
-// this.queryid = queryid;
-// }
-
public String getDescription() {
return description;
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/OldUser.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/OldUser.java
index e458064b2fe1292fabbabef60a5a9449cab299cb..3a7da924978db41e788d8c5c2fdf20440087a1d9 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/OldUser.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/OldUser.java
@@ -29,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonManagedReference;
public class OldUser {
@Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @GeneratedValue(strategy = GenerationType.AUTO)
private Long userid;
@JsonAlias({ "preferred_username", "username" })
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/ParametricQuery.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/ParametricQuery.java
new file mode 100644
index 0000000000000000000000000000000000000000..094f39e04466518e2482566529ac9dd4c1a4f2b1
--- /dev/null
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/ParametricQuery.java
@@ -0,0 +1,79 @@
+package it.enea.cruise.model.user;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.FetchMode;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+@Getter
+@Setter
+@Entity
+@Table(name = "parametricquery", schema = "cruise")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class ParametricQuery {
+
+ @Id
+ @Column(name = "queryid")
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+
+ private String name;
+ private String sql;
+ private String description;
+ @Column(name = "querytype")
+ private String queryType; // {SQL, API};
+
+ @Transient
+ @JsonProperty("metadata")
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ List> parameterMetadata;
+
+ @ManyToMany
+ @JoinTable(
+ schema = "cruise",
+ name = "queries_parameters",
+ joinColumns = @JoinColumn
+ (name = "queryid"),
+ inverseJoinColumns = @JoinColumn(name = "paramid"))
+ @Fetch(FetchMode.SUBSELECT)
+ @JsonProperty("parameters")
+ @JsonIgnoreProperties("parametricquery")
+ private List parameters;
+
+ @ManyToMany
+ @JoinTable(
+ schema = "cruise",
+ name = "queries_admittedqueryvalues",
+ joinColumns = @JoinColumn(name = "queryid"),
+ inverseJoinColumns = @JoinColumn(name = "admittedqueryvalueid"))
+ private List admittedqueryvalues;
+
+ @Transient
+ Map> values = new HashMap<>();
+
+ @PostLoad
+ public void postLoad() {
+ for (AdmittedQueryValues aqv : admittedqueryvalues) {
+ List tempList;
+ if (values.containsKey(aqv.getType())) {
+ tempList = values.get(aqv.getType());
+ tempList.add(aqv.getValue());
+
+ } else {
+ tempList = new ArrayList();
+ tempList.add(aqv.getValue());
+ }
+ values.put(aqv.getType(), tempList);
+ }
+ }
+}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/Role.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/Role.java
index 919f79447dc805d4a345ade008f798e7dc8a3755..17698fc82e75ef18420fd2a2e9d84f57c95d16f9 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/Role.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/Role.java
@@ -1,24 +1,17 @@
package it.enea.cruise.model.user;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
-
import lombok.Getter;
import lombok.Setter;
-@Entity(name = "role")
-@Table(name = "t_roles")
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
+
+@Entity
@Getter
@Setter
+@Table(name = "t_roles")
public class Role {
@Id
@@ -33,39 +26,6 @@ public class Role {
@JsonIgnore
private List userRoles = new ArrayList<>();
-
-// public Long getId() {
-// return id;
-// }
-//
-// public void setId(Long id) {
-// this.id = id;
-// }
-//
-// public String getDescription() {
-// return description;
-// }
-//
-// public void setDescription(String description) {
-// this.description = description;
-// }
-//
-// public String getRolename() {
-// return rolename;
-// }
-//
-// public void setRolename(String roleName) {
-// this.rolename = roleName;
-// }
-//
-// public List getUserRoles() {
-// return userRoles;
-// }
-//
-// public void setUserRoles(List userRoles) {
-// this.userRoles = userRoles;
-// }
-
@Override
public String toString() {
String result = "{\"id\":" + this.id + ","
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/User.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/User.java
index 627f400327acb5d40c29808be0348494ef775011..dd055f7ec8ebde125260cc266449bf5ee488a7e3 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/User.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/User.java
@@ -1,34 +1,28 @@
package it.enea.cruise.model.user;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.*;
-
+import com.fasterxml.jackson.annotation.*;
+import it.enea.cruise.dto.UserToken;
import it.enea.scp.idp.sdk.model.UserDto;
+import lombok.Getter;
+import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-import lombok.Getter;
-import lombok.Setter;
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
@Getter
@Setter
-@Entity(name = "user")
-@Table(name = "Users")
+@Entity
+@Table(name = "users")
@Access(AccessType.FIELD)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "userid")
public class User {
@Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @GeneratedValue(strategy = GenerationType.AUTO)
private Long userid;
private String subject;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunity.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunity.java
index 4fe5e2f0524d4e64c43952bb598bc790516d98ac..71e7979a6b5ba1582347277ccc2e37eeeedf3547 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunity.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunity.java
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
*
*/
-@Entity(name = "userCommunity")
+@Entity
@Table(name = "users_communities")
public class UserCommunity {
@@ -71,7 +71,7 @@ public class UserCommunity {
public UserCommunity(User user, Community community) {
this.user = user;
this.community = community;
- this.id = new UserCommunityId(user.getUserid(), community.getCommunityid());
+ this.id = new UserCommunityId(user.getUserid(), community.getId());
}
/*
@@ -108,21 +108,10 @@ public class UserCommunity {
}
public void setCommunity(Community community) {
- id.setCommunityId(community.getCommunityid());
+ id.setCommunityId(community.getId());
this.community = community;
}
-// @Override
-// public String toString() {
-// String result = "";
-// result = "{\"user\" : " + this.user.getUserid() + ","
-// + "\"community\" : " + this.community.getCommunityid() + ","
-// + "\"wallet\" : \"" + this.wallet +"\""
-// + "}";
-//
-// return result;
-// }
-
public void clear() {
this.user = null;
this.community = null;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunityId.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunityId.java
index 2a023e98153b5e8dee930cea98b2fb6a4e1ced4a..a1e6be7d44364d9812f0da5b2ee5f4779c4403a9 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunityId.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserCommunityId.java
@@ -7,81 +7,69 @@ import javax.persistence.Embeddable;
import javax.persistence.Transient;
/**
- *
* @author gianluca
- * Questa classe rappresenta l'ID della tabella users_communities che
- * non esiste all'interno del DB.
- * Attraverso questa classe e' possibile creare una relazione tra Users e
+ * Questa classe rappresenta l'ID della tabella users_communities che
+ * non esiste all'interno del DB.
+ * Attraverso questa classe e' possibile creare una relazione tra Users e
* Communities che contenga anche altre informazioni.
* I dati di questa classe vengono registrati all'interno dell'oggetto
* UserCommunity in cui questa classe e' inserita.
*/
@Embeddable
public class UserCommunityId implements Serializable {
-
+
/*
- * Properties
- */
- @Transient
- private static final long serialVersionUID = 1L;
-
- @Column ( name = "userid")
- private Long userid;
- @Column ( name = "communityid")
- private Long communityid;
-
- /*
- * Generic Methods
- */
-
- public UserCommunityId() {}
-
+ * Properties
+ */
+ @Transient
+ private static final long serialVersionUID = 1L;
+
+ @Column(name = "userid")
+ private Long userid;
+ @Column(name = "communityid")
+ private Long communityid;
+
+ /*
+ * Generic Methods
+ */
+
+ public UserCommunityId() {
+ }
+
public UserCommunityId(
- Long userId,
- Long communityid) {
+ Long userId,
+ Long communityid) {
this.setUserId(userId);
this.setCommunityId(communityid);
}
-
- public boolean equals(UserCommunityId o) {
- Boolean result = false;
-
- if (o == null)
- result = false;
-
- if (this.communityid.equals(o.communityid) &&
- this.userid.equals(o.userid)) {
- result = true;
+
+ public boolean equals(UserCommunityId o) {
+ Boolean result = false;
+
+ if (o == null)
+ result = false;
+
+ if (this.communityid.equals(o.communityid) &&
+ this.userid.equals(o.userid)) {
+ result = true;
}
-
-
-
+
return result;
-
}
-
- //@Override
- // public int hashCode() {
- // return Objects.hash(this);
- // }
- /*
- * Getters and setters
- */
-
- public Long getUserId() {
- return userid;
- }
-
- public void setUserId(Long userId) {
- this.userid = userId;
- }
-
- public Long getCommunityId() {
- return communityid;
- }
-
- public void setCommunityId(Long communityId) {
- this.communityid = communityId;
- }
+ public Long getUserId() {
+ return userid;
+ }
+
+ public void setUserId(Long userId) {
+ this.userid = userId;
+ }
+
+ public Long getCommunityId() {
+ return communityid;
+ }
+
+ public void setCommunityId(Long communityId) {
+ this.communityid = communityId;
+ }
}
\ No newline at end of file
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRole.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRole.java
index 1857caade4cd001c0a146df3c4fcfea693928f10..96779cf05355ca47e69d27c2a02ff3ea264bd519 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRole.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRole.java
@@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
*
*/
-@Entity(name = "userRole")
+@Entity
@Table(name = "users_roles")
public class UserRole {
@@ -65,7 +65,7 @@ public class UserRole {
this.user = user;
this.role = role;
this.community = community;
- this.id = new UserRoleId(user.getUserid(), role.getId(), community.getCommunityid());
+ this.id = new UserRoleId(user.getUserid(), role.getId(), community.getId());
}
// public UserRole(User user, Role role, Long communityid) {
@@ -81,7 +81,7 @@ public class UserRole {
*/
public Long getCommunityid() {
- return community.getCommunityid();
+ return community.getId();
}
public UserRoleId getId() {
@@ -115,7 +115,7 @@ public class UserRole {
}
public void setCommunity(Community community) {
- id.setCommunityId(community.getCommunityid());
+ id.setCommunityId(community.getId());
this.community = community;
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRoleId.java b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRoleId.java
index 8b73f03f4d83f488f94e6db05fa714b47b5c86e4..f8d0868ee982b7ac892fea187630ed29ed093fab 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRoleId.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/model/user/UserRoleId.java
@@ -8,87 +8,83 @@ import javax.persistence.Embeddable;
import javax.persistence.Transient;
/**
- *
* @author gianluca
- * Questa classe rappresenta l'ID della tabella users_communities che
- * non esiste all'interno del DB.
- * Attraverso questa classe e' possibile creare una relazione tra Users e
+ * Questa classe rappresenta l'ID della tabella users_communities che
+ * non esiste all'interno del DB.
+ * Attraverso questa classe e' possibile creare una relazione tra Users e
* Communities che contenga anche altre informazioni.
* I dati di questa classe vengono registrati all'interno dell'oggetto
* UserCommunity in cui questa classe e' inserita.
*/
@Embeddable
public class UserRoleId implements Serializable {
-
+
/*
- * Properties
- */
- @Transient
- private static final long serialVersionUID = 1L;
+ * Properties
+ */
+ @Transient
+ private static final long serialVersionUID = 1L;
- @Column ( name = "userid")
+ @Column(name = "userid")
private Long userid;
- @Column ( name = "roleid")
+ @Column(name = "roleid")
private Long roleid;
- @Column ( name = "communityid")
+ @Column(name = "communityid")
private Long communityid;
- /*
- * Generic Methods
- */
-
- public UserRoleId() {}
-
+ public UserRoleId() {
+ }
+
public UserRoleId(
- Long userId,
- Long roleid,
- Long communityid) {
+ Long userId,
+ Long roleid,
+ Long communityid) {
this.setUserId(userId);
this.setRoleId(roleid);
this.setCommunityId(communityid);
}
-
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
-
+
if (o == null || getClass() != o.getClass())
return false;
-
+
UserRoleId that = (UserRoleId) o;
return Objects.equals(this, that);
}
-
+
@Override
public int hashCode() {
return Objects.hash(this);
}
/*
- * Getters and setters
- */
-
- public Long getUserId() {
- return userid;
- }
-
- public void setUserId(Long userId) {
- this.userid = userId;
- }
-
- public Long getRoleId() {
- return roleid;
- }
-
- public void setRoleId(Long roleid) {
- this.roleid = roleid;
- }
-
- public Long getCommunityId() {
- return communityid;
- }
-
- public void setCommunityId(Long communityid) {
- this.communityid = communityid;
- }
+ * Getters and setters
+ */
+
+ public Long getUserId() {
+ return userid;
+ }
+
+ public void setUserId(Long userId) {
+ this.userid = userId;
+ }
+
+ public Long getRoleId() {
+ return roleid;
+ }
+
+ public void setRoleId(Long roleid) {
+ this.roleid = roleid;
+ }
+
+ public Long getCommunityId() {
+ return communityid;
+ }
+
+ public void setCommunityId(Long communityid) {
+ this.communityid = communityid;
+ }
}
\ No newline at end of file
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/DTOManager.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/DTOManager.java
index c5066546177ec1e91e69f644dcd8e8582c2ac78b..74fe390a2af2c9a0489d2f78249fe51e3da00dc3 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/DTOManager.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/DTOManager.java
@@ -16,7 +16,7 @@ import it.enea.cruise.dto.CommunityDTO;
import it.enea.cruise.dto.DeviceDTO;
import it.enea.cruise.dto.LocalUserDTO;
import it.enea.cruise.dto.MetadataDTO;
-import it.enea.cruise.model.structure.ColumnCommentDTO;
+import it.enea.cruise.dto.ColumnCommentDTO;
import it.enea.cruise.model.structure.VwTableMetadata;
import it.enea.cruise.model.user.Community;
import it.enea.cruise.model.user.Device;
@@ -53,7 +53,7 @@ public class DTOManager {
public CommunityDTO communityDTO(UserCommunity c) {
CommunityDTO communityDTO = new CommunityDTO();
log.info("preparing CommunityTO for export");
- communityDTO.setCommunityid(c.getCommunity().getCommunityid());
+ communityDTO.setCommunityid(c.getCommunity().getId());
communityDTO.setDescription(c.getCommunity().getDescription());
communityDTO.setWallet(c.getWallet() != null ? c.getWallet().toString() : "noWallet");
communityDTO.setCommunityName(c.getCommunity().getCommunityName());
@@ -64,7 +64,7 @@ public class DTOManager {
public CommunityDTO communityDTO(Community c) {
CommunityDTO communityDTO = new CommunityDTO();
log.info("preparing CommunityTO for export");
- communityDTO.setCommunityid(c.getCommunityid());
+ communityDTO.setCommunityid(c.getId());
communityDTO.setDescription(c.getDescription());
communityDTO.setWallet("noWallet");
communityDTO.setCommunityName(c.getCommunityName());
@@ -79,7 +79,7 @@ public class DTOManager {
deviceDTO.setActivationdate(d.getActivationdate());
deviceDTO.setAltdeviceid(d.getAltdeviceid());
deviceDTO.setDescription(d.getDescription());
- deviceDTO.setDeviceid(d.getDeviceid());
+ deviceDTO.setDeviceid(d.getId());
deviceDTO.setDevicename(d.getDevicename());
deviceDTO.setDevicestatus(d.getDevicestatus());
deviceDTO.setDevicetype(d.getDevicetype());
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/data/DataInterface.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/data/DataConsumptionRepository.java
similarity index 87%
rename from gecoregistration/src/main/java/it/enea/cruise/service/data/DataInterface.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/data/DataConsumptionRepository.java
index 890fa6953d71901fb288828e21133346b6f63920..3546281248afabe5d5d269d63ef3461a7a2e8218 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/data/DataInterface.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/data/DataConsumptionRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.service.data;
+package it.enea.cruise.repositories.data;
import java.util.Date;
import java.util.List;
@@ -9,9 +9,9 @@ import org.springframework.data.repository.query.Param;
import it.enea.cruise.model.data.DataConsumption;
-public interface DataInterface extends JpaRepository {
+public interface DataConsumptionRepository extends JpaRepository {
- @Query("SELECT dc FROM dataConsumption dc "
+ @Query("SELECT dc FROM DataConsumption dc "
+ "WHERE dc.userid = :userid "
+ "AND dc.timestamp >= :startDate "
+ "AND dc.timestamp < :endDate "
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/CommunityRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/CommunityRepository.java
similarity index 73%
rename from gecoregistration/src/main/java/it/enea/cruise/repositories/CommunityRepository.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/CommunityRepository.java
index 587f6fc08d237ed8a09fd60614c0662f1af9cd18..26a6c89be838560e88e9e16577462693cb423499 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/CommunityRepository.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/CommunityRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.repositories;
+package it.enea.cruise.repositories.user;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -6,6 +6,5 @@ import it.enea.cruise.model.user.Community;
public interface CommunityRepository extends JpaRepository {
Community findByCommunityName(String communityName);
- Community findByCommunityid(Long communityId);
}
\ No newline at end of file
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/structure/ForeignKeyInterface.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/ForeignKeyRepository.java
similarity index 84%
rename from gecoregistration/src/main/java/it/enea/cruise/service/structure/ForeignKeyInterface.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/ForeignKeyRepository.java
index 34920149bcd53c3511277405656450e263898158..1989a18401878ace8a9119e5fb1d3ac6610afa95 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/structure/ForeignKeyInterface.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/ForeignKeyRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.service.structure;
+package it.enea.cruise.repositories.user;
import java.util.List;
@@ -8,7 +8,7 @@ import org.springframework.data.repository.query.Param;
import it.enea.cruise.model.structure.ForeignKey;
-public interface ForeignKeyInterface extends JpaRepository {
+public interface ForeignKeyRepository extends JpaRepository {
List findByTableName (String tableName);
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/user/LocalQueryParameterRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/LocalQueryParameterRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..bbe354685b010f2cfa68a9ae91b0007093a70489
--- /dev/null
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/LocalQueryParameterRepository.java
@@ -0,0 +1,13 @@
+package it.enea.cruise.repositories.user;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import it.enea.cruise.model.user.LocalQueryParameter;
+
+public interface LocalQueryParameterRepository extends JpaRepository{
+
+ List findAllByName(String paramName);
+
+}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/OldUserRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/OldUserRepository.java
similarity index 93%
rename from gecoregistration/src/main/java/it/enea/cruise/repositories/OldUserRepository.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/OldUserRepository.java
index a139a1c7a88097427411831c36ca1bae96e9c1c9..f25af02b1b296e0d8cdb15250eae9205b5724b12 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/OldUserRepository.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/OldUserRepository.java
@@ -1,4 +1,5 @@
-package it.enea.cruise.repositories;
+/*
+package it.enea.cruise.repositories.user;
import java.util.List;
@@ -24,3 +25,4 @@ public interface OldUserRepository extends CrudRepository{
User findBySubject(String subject);
}
+*/
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/user/ParametricQueryRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/ParametricQueryRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..d3f1105004fa11b8126174decb7399f3fc2d24d3
--- /dev/null
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/ParametricQueryRepository.java
@@ -0,0 +1,12 @@
+package it.enea.cruise.repositories.user;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import it.enea.cruise.model.user.ParametricQuery;
+
+public interface ParametricQueryRepository extends JpaRepository {
+ List findAll();
+}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/RoleRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/RoleRepository.java
similarity index 90%
rename from gecoregistration/src/main/java/it/enea/cruise/repositories/RoleRepository.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/RoleRepository.java
index 5f88736ac50b451230f2a51415a58a1009948080..3aa4b3a5ff9b3858bb9941d44d41c41239d86f5d 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/RoleRepository.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/RoleRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.repositories;
+package it.enea.cruise.repositories.user;
import java.util.List;
import java.util.Optional;
@@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import it.enea.cruise.model.user.Role;
-public interface RoleRepository extends JpaRepository{
+public interface RoleRepository extends JpaRepository {
List findAllByDescription(String description);
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/structure/TableMetadataInterface.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/TableMetadataRepository.java
similarity index 67%
rename from gecoregistration/src/main/java/it/enea/cruise/service/structure/TableMetadataInterface.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/TableMetadataRepository.java
index 1129c13f1f30af814558f3c304ec1c64ca254b26..f4f696e349a51e2b7008ca475f8749fefc766f71 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/structure/TableMetadataInterface.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/TableMetadataRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.service.structure;
+package it.enea.cruise.repositories.user;
import java.util.List;
@@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import it.enea.cruise.model.structure.VwTableMetadata;
-public interface TableMetadataInterface extends JpaRepository
+public interface TableMetadataRepository extends JpaRepository
{
List findByTableName(String tableName);
List findByColumnName(String columnName);
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/UserCommunityRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserCommunityRepository.java
similarity index 82%
rename from gecoregistration/src/main/java/it/enea/cruise/repositories/UserCommunityRepository.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserCommunityRepository.java
index 6f74025636c537a5b573c93bf2a6574d49d80b4d..09b771d848a31bdf2c677e4d090a8105a8c9deb9 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/UserCommunityRepository.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserCommunityRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.repositories;
+package it.enea.cruise.repositories.user;
import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/UserRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserRepository.java
similarity index 74%
rename from gecoregistration/src/main/java/it/enea/cruise/repositories/UserRepository.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserRepository.java
index 99a5b498a55deec575ad8ef1b61117a47d834866..593ec8cd4085aeddcf95b184d74a9156da8d1bb6 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/UserRepository.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.repositories;
+package it.enea.cruise.repositories.user;
import java.util.List;
import java.util.Optional;
@@ -19,31 +19,31 @@ public interface UserRepository extends JpaRepository{
@Transactional(noRollbackFor=Exception.class)
User findBySubject(String subject);
- @Query ("SELECT u FROM user as u JOIN userCommunity as uc ON u.userid = uc.id.userid WHERE uc.id.communityid = ?1")
+ @Query ("SELECT u FROM User as u JOIN UserCommunity as uc ON u.userid = uc.id.userid WHERE uc.id.communityid = ?1")
List findAllByCommunityId(Long communityid);
- @Query("Select d from device d WHERE d.user.userid = :userid")
+ @Query("Select d from Device d WHERE d.user.userid = :userid")
List findAllDevicesByUserid(@Param("userid") Long userid);
- @Query("Select u from user as u WHERE u.subject LIKE :subject")
+ @Query("Select u from User as u WHERE u.subject LIKE :subject")
User findUserBySubject(@Param("subject") String subject);
List findBySubjectIsNotNull();
- @Query ("SELECT u FROM user as u JOIN userCommunity as uc ON u.userid = uc.id.userid WHERE u.subject IS NOT NULL AND uc.id.communityid = ?1")
+ @Query ("SELECT u FROM User as u JOIN UserCommunity as uc ON u.userid = uc.id.userid WHERE u.subject IS NOT NULL AND uc.id.communityid = ?1")
List findBySubjectIsNotNullAndCommunityId(Long communityid);
- @Query ("SELECT u FROM user as u JOIN userCommunity as uc ON u.userid = uc.id.userid WHERE u.subject IS NOT NULL AND uc.active = TRUE AND uc.id.communityid = ?1")
+ @Query ("SELECT u FROM User as u JOIN UserCommunity as uc ON u.userid = uc.id.userid WHERE u.subject IS NOT NULL AND uc.active = TRUE AND uc.id.communityid = ?1")
List findBySubjectIsNotNullAndActiveIsTrueAndCommunityId(Long communityid);
- @Query ("SELECT count(*) FROM user as u JOIN userCommunity as uc ON u.userid = uc.id.userid WHERE u.subject IS NOT NULL AND uc.id.communityid = ?1")
+ @Query ("SELECT count(*) FROM User as u JOIN UserCommunity as uc ON u.userid = uc.id.userid WHERE u.subject IS NOT NULL AND uc.id.communityid = ?1")
Integer countBySubjectIsNotNullAndCommunityId(Long communityid);
- @Query ("SELECT u FROM user as u JOIN userCommunity as uc ON u.userid = uc.id.userid WHERE uc.wallet = ?1")
+ @Query ("SELECT u FROM User as u JOIN UserCommunity as uc ON u.userid = uc.id.userid WHERE uc.wallet = ?1")
List findFromWallet(String wallet);
- @Query ("SELECT u FROM user as u JOIN userCommunity as uc ON u.userid = uc.id.userid WHERE uc.wallet = ?1 AND uc.id.communityid = ?2")
+ @Query ("SELECT u FROM User as u JOIN UserCommunity as uc ON u.userid = uc.id.userid WHERE uc.wallet = ?1 AND uc.id.communityid = ?2")
List findFromWalletAndCommunityId(String wallet, Long communityid);
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/repositories/UserRoleRepository.java b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserRoleRepository.java
similarity index 81%
rename from gecoregistration/src/main/java/it/enea/cruise/repositories/UserRoleRepository.java
rename to gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserRoleRepository.java
index 587f7d060e7742d777576b249a7cb6eb2c7950e7..ea2169808c0971faaf3956d0f738e7815fd82405 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/repositories/UserRoleRepository.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/repositories/user/UserRoleRepository.java
@@ -1,4 +1,4 @@
-package it.enea.cruise.repositories;
+package it.enea.cruise.repositories.user;
import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/data/DataCacher.java b/gecoregistration/src/main/java/it/enea/cruise/service/data/DataCacher.java
index e4e8a7fe11429b197b1bd49e0a3d02d68065c876..78cfdcc7d4bedfc89dc01be63bd608e1142bf848 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/data/DataCacher.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/data/DataCacher.java
@@ -7,8 +7,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.stereotype.Component;
@Component
-public class DataCacher
- implements CacheManagerCustomizer {
+public class DataCacher implements CacheManagerCustomizer {
@Override
public void customize(ConcurrentMapCacheManager cacheManager) {
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/data/DataService.java b/gecoregistration/src/main/java/it/enea/cruise/service/data/DataService.java
index a0e44cff2105dd479fd270fed3b3666bb75e3d9c..636a9ae60940371a4c0be4c765b04eebfaf8608b 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/data/DataService.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/data/DataService.java
@@ -1,19 +1,21 @@
package it.enea.cruise.service.data;
import java.util.Map;
+import java.util.Optional;
import it.enea.cruise.exceptions.TokenNotValidException;
+import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import it.enea.cruise.model.parametricQuery.ParametricQuery;
+import it.enea.cruise.model.user.ParametricQuery;
import it.enea.cruise.model.user.User;
import it.enea.cruise.service.idp.IdpProvider;
-import it.enea.cruise.service.parametricQuery.LocalQueryParameterInterface;
-import it.enea.cruise.service.parametricQuery.ParametricQueryInterface;
+import it.enea.cruise.repositories.user.LocalQueryParameterRepository;
+import it.enea.cruise.repositories.user.ParametricQueryRepository;
import it.enea.cruise.service.parametricQuery.ParametricQueryManager;
import it.enea.cruise.service.parametricQuery.ParametricQueryManager.ResultWithMetadata;
-import it.enea.cruise.repositories.UserRepository;
+import it.enea.cruise.repositories.user.UserRepository;
import lombok.extern.log4j.Log4j2;
import javax.transaction.Transactional;
@@ -21,23 +23,12 @@ import javax.transaction.Transactional;
@Service
@Log4j2
+@RequiredArgsConstructor
public class DataService implements IDataService {
- @Autowired
- LocalQueryParameterInterface lqpInterface;
-
- @Autowired
- UserRepository userInterface;
-
-
- @Autowired
- ParametricQueryInterface pqueryInterface;
-
-
- @Autowired
- ParametricQueryManager pqm;
-
- @Autowired
- IdpProvider idpClientManager;
+ private final UserRepository userInterface;
+ private final ParametricQueryRepository pqueryInterface;
+ private final ParametricQueryManager pqm;
+ private final IdpProvider idpClientManager;
@Override
@Transactional
@@ -47,16 +38,13 @@ public class DataService implements IDataService {
String language) {
log.info("Input data:" + inputData.toString());
+ log.info("Token to check:" + token);
if (idpClientManager.isValid(token)) {
-
User userdto = idpClientManager.getUserByToken(token);
-
User user = userInterface.findBySubject(userdto.getUuid());
-
inputData.put("userid", user.getUserid().toString());
-
- ParametricQuery pq = pqueryInterface.findByQueryid(new Long(inputData.get("queryid")));
- return pqm.executeQuery(pq, inputData, language);
+ Optional pq = pqueryInterface.findById(Long.valueOf(inputData.get("queryid")));
+ return pq.isPresent() ? pqm.executeQuery(pq.get(), inputData, language) : new ResultWithMetadata();
}
log.info("Warning: token is not valid");
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/idp/EneaProvider.java b/gecoregistration/src/main/java/it/enea/cruise/service/idp/EneaProvider.java
index 46596a7142a5a014ee5936c843384adb491fb952..d71789c66b016523991af31deb5b0e09187445f3 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/idp/EneaProvider.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/idp/EneaProvider.java
@@ -21,7 +21,7 @@ import it.enea.scp.idp.sdk.model.TokenValidityResponse;
import it.enea.scp.idp.sdk.model.UpdateUserRequest;
import it.enea.scp.idp.sdk.model.UserDto;
import it.enea.cruise.model.user.User;
-import it.enea.cruise.model.user.UserToken;
+import it.enea.cruise.dto.UserToken;
import lombok.extern.log4j.Log4j2;
@Log4j2
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/idp/IEncryptionManager.java b/gecoregistration/src/main/java/it/enea/cruise/service/idp/IEncryptionManager.java
index da425e6d7eb0eb4e95efc8af6d124cd96581869c..c2289e4cf347beba7807e59d24f254ce5eaf8bbb 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/idp/IEncryptionManager.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/idp/IEncryptionManager.java
@@ -1,14 +1,8 @@
package it.enea.cruise.service.idp;
public interface IEncryptionManager {
-
-
- public void init(String password);
-
- public void init();
-
- public String encrypt(String s);
-
- public String decrypt(String s);
-
+ void init(String password);
+ void init();
+ String encrypt(String s);
+ String decrypt(String s);
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/idp/IdpCachedProvider.java b/gecoregistration/src/main/java/it/enea/cruise/service/idp/IdpCachedProvider.java
index 32bee23c5a51c1837a49284dbafe7b0f6bb7f9f3..40fcd4f332c1826bab92484d1b7f37ef6d04d776 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/idp/IdpCachedProvider.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/idp/IdpCachedProvider.java
@@ -13,75 +13,75 @@ import org.springframework.stereotype.Service;
@Service
@Log4j2
-@Profile("test")
+@Profile("none")
public class IdpCachedProvider extends EneaProvider implements IdpProvider {
-
- /*@Autowired*/
- EneaProvider idpClientManager;
-
- @Override
- public String getTokenFromUsernameAndPassword(String username, String password) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- //@Cacheable(value="users", key="#username")
- public User login(String username, String password) {
- log.info("logging");
- return super.login(username, password);
- // TODO Auto-generated method stub
- }
-
- @Override
- public boolean logout(String token) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isValid(String token) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public List userList() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Boolean deleteUser(String email) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Boolean createUser(UserDto newUser) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public UserDto getUserByEmail(String email) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- @Cacheable(value="users",key="#token")
- public User getUserByToken(String token) {
- log.info("getting user with token: " + token);
- return super.getUserByToken(token);
-
- }
-
- @Override
- public Boolean updateUser(UserDto user) {
- // TODO Auto-generated method stub
- return null;
- }
+
+ /*@Autowired*/
+ EneaProvider idpClientManager;
+
+ @Override
+ public String getTokenFromUsernameAndPassword(String username, String password) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ //@Cacheable(value="users", key="#username")
+ public User login(String username, String password) {
+ log.info("logging");
+ return super.login(username, password);
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public boolean logout(String token) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isValid(String token) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public List userList() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Boolean deleteUser(String email) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Boolean createUser(UserDto newUser) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UserDto getUserByEmail(String email) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ @Cacheable(value = "users", key = "#token")
+ public User getUserByToken(String token) {
+ log.info("getting user with token: " + token);
+ return super.getUserByToken(token);
+
+ }
+
+ @Override
+ public Boolean updateUser(UserDto user) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/idp/KeycloakProvider.java b/gecoregistration/src/main/java/it/enea/cruise/service/idp/KeycloakProvider.java
index 98ce9b58b05cd14416e188e38f89d908591976ec..26314654fe8740be087bb368b225b07602ab5e20 100644
--- a/gecoregistration/src/main/java/it/enea/cruise/service/idp/KeycloakProvider.java
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/idp/KeycloakProvider.java
@@ -1,7 +1,7 @@
package it.enea.cruise.service.idp;
import it.enea.cruise.exceptions.TokenNotValidException;
-import it.enea.cruise.repositories.UserRepository;
+import it.enea.cruise.repositories.user.UserRepository;
import it.enea.scp.idp.sdk.model.UserDto;
import it.enea.cruise.model.user.User;
import lombok.RequiredArgsConstructor;
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/idp/TestIdpClient.java b/gecoregistration/src/main/java/it/enea/cruise/service/idp/TestIdpClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..97b784e0d5935004eb8b20342801a3d1c8087e6a
--- /dev/null
+++ b/gecoregistration/src/main/java/it/enea/cruise/service/idp/TestIdpClient.java
@@ -0,0 +1,105 @@
+package it.enea.cruise.service.idp;
+
+import it.enea.cruise.dto.UserToken;
+import it.enea.cruise.model.user.User;
+import it.enea.scp.idp.sdk.model.UserDto;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Profile;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+@Profile("test")
+@Transactional
+public class TestIdpClient implements IdpProvider {
+ @Value("${idp.testAdminEmail}")
+ String userAdminEmail;
+
+ @Value("${idp.testAdminPwd}")
+ String userAdminPwd;
+
+ @Value("${idp.testUserEmail}")
+ String testUserEmail;
+
+ @Value("${idp.testUserPwd}")
+ String testUserPwd;
+
+ private User user = new User();
+
+ @Override
+ public String getTokenFromUsernameAndPassword(String username, String password) {
+ return "the_token";
+ }
+
+ @Override
+ public User login(String username, String password) {
+ if (!userAdminEmail.equalsIgnoreCase(username) && !testUserEmail.equalsIgnoreCase(username)) return null;
+
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+ cal.add(Calendar.MINUTE, 10);
+ user.setToken(UserToken.builder().creation(new Date()).value("the_token").expiration(cal.getTime()).build());
+ user.setUsername(username);
+ return user;
+ }
+
+ @Override
+ public User getUserByToken(String token) {
+ return user;
+ }
+
+ @Override
+ public UserDto getUserByEmail(String email) {
+ UserDto user = new UserDto();
+ user.setEmail(email);
+ return user;
+ }
+
+ @Override
+ public boolean logout(String token) {
+ return true;
+ }
+
+ @Override
+ public boolean isValid(String token) {
+ return true;
+ }
+
+ @Override
+ public List userList() {
+ return List.of();
+ }
+
+ @Override
+ public Boolean deleteUser(String email) {
+ return null;
+ }
+
+ @Override
+ public Boolean createUser(UserDto newUser) {
+ return null;
+ }
+
+ @Override
+ public Boolean updateUser(UserDto user) {
+ return null;
+ }
+
+ @Override
+ public UserDto getUserFromUUID(String uuid) {
+ return null;
+ }
+
+ @Override
+ public Boolean updatePassword(String token, String password) {
+ return null;
+ }
+}
diff --git a/gecoregistration/src/main/java/it/enea/cruise/service/parametricQuery/LocalQueryParameterInterface.java b/gecoregistration/src/main/java/it/enea/cruise/service/parametricQuery/LocalQueryParameterInterface.java
deleted file mode 100644
index c8a632d69a5ce8faebe5cea2da5044b4419b676a..0000000000000000000000000000000000000000
--- a/gecoregistration/src/main/java/it/enea/cruise/service/parametricQuery/LocalQueryParameterInterface.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package it.enea.cruise.service.parametricQuery;
-
-import java.util.List;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-
-import it.enea.cruise.model.parametricQuery.LocalQueryParameter;
-
-public interface LocalQueryParameterInterface extends JpaRepository{
-
- List