use of org.geosdi.geoplatform.core.model.GPUser in project geo-platform by geosdi.
the class LayerService method shareProjectToUsers.
@Override
public boolean shareProjectToUsers(long idSharedProject, List<Long> accountIDsProject, HttpServletRequest httpServletRequest) throws GeoPlatformException {
boolean result;
try {
GPAccount account = this.sessionUtility.getLoggedAccount(httpServletRequest);
result = this.geoPlatformServiceClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idSharedProject, accountIDsProject));
if (result) {
MessageDTO message = new MessageDTO();
message.setCommands(Lists.newArrayList(GPMessageCommandType.OPEN_PROJECT));
message.setCommandsProperties("" + idSharedProject);
message.setCreationDate(new Date());
message.setSenderID(account.getId());
message.setSubject("Project Shared");
String sharerName;
if (account instanceof GPUser) {
GPUser user = (GPUser) account;
sharerName = user.getName();
} else {
sharerName = account.getNaturalID();
}
GPProject project = this.geoPlatformServiceClient.getProjectDetail(idSharedProject);
message.setText(sharerName + " shared with you the " + project.getName() + " project. Do you want to open it?");
message.setRecipientIDs(accountIDsProject);
this.geoPlatformServiceClient.insertMultiMessage(message);
}
} catch (GPSessionTimeout timeout) {
throw new GeoPlatformException(timeout);
} catch (ResourceNotFoundFault | IllegalParameterFault rnf) {
logger.error("Failed to save Shared project to Accounts for Shared Project with id: " + idSharedProject + "on SecurityService: " + rnf);
throw new GeoPlatformException(rnf);
}
return result;
}
use of org.geosdi.geoplatform.core.model.GPUser in project geo-platform by geosdi.
the class GPAccountDAOImpl method searchPagebleEnabledUsersByOrganization.
/**
* @param page
* @param size
* @param organizationName
* @param userID
* @param nameLike
* @return {@link List<GPAccount>}
* @throws GPDAOException
*/
@Override
public List<GPAccount> searchPagebleEnabledUsersByOrganization(Integer page, Integer size, String organizationName, Long userID, String nameLike) throws GPDAOException {
checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Paramater organizationName must not be null or an Empty String.");
checkArgument(userID != null, "The Parameter userID must not be null.");
try {
CriteriaBuilder builder = super.criteriaBuilder();
CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
Root<GPUser> userRoot = builder.treat(root, GPUser.class);
criteriaQuery.select(root);
List<Predicate> predicates = Lists.newArrayList();
if ((nameLike != null) && !(nameLike.trim().isEmpty()))
predicates.add(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()));
predicates.add(builder.equal(root.get("enabled"), TRUE));
predicates.add(builder.equal(root.join("organization").get("name"), organizationName));
predicates.add(builder.notEqual(root.get("id"), userID));
predicates.add(builder.isNotNull(userRoot.get("username")));
criteriaQuery.where(predicates.stream().toArray(Predicate[]::new)).orderBy(builder.asc(userRoot.get("username")));
Query typedQuery = this.entityManager.createQuery(criteriaQuery);
Integer firstResult = (page == 0) ? 0 : ((page * size));
typedQuery.setFirstResult(firstResult);
typedQuery.setMaxResults(size);
return typedQuery.getResultList();
} catch (Exception ex) {
ex.printStackTrace();
throw new GPDAOException(ex);
}
}
use of org.geosdi.geoplatform.core.model.GPUser in project geo-platform by geosdi.
the class GPAccountDAOImpl method findByUsername.
/**
* @param username
* @return {@link GPUser}
* @throws Exception
*/
@Override
public GPUser findByUsername(String username) throws GPDAOException {
checkArgument((username != null) && !(username.trim().isEmpty()), "The Parameter username must not be null or an empty String.");
try {
CriteriaBuilder builder = super.criteriaBuilder();
CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
Root<GPUser> userRoot = builder.treat(root, GPUser.class);
criteriaQuery.select(root);
criteriaQuery.where(super.criteriaBuilder().equal(userRoot.get("username"), username));
List<GPAccount> accounts = this.entityManager.createQuery(criteriaQuery).getResultList();
return ((accounts != null) && !(accounts.isEmpty()) ? (GPUser) accounts.get(0) : null);
} catch (Exception ex) {
ex.printStackTrace();
throw new GPDAOException(ex);
}
}
use of org.geosdi.geoplatform.core.model.GPUser in project geo-platform by geosdi.
the class GPAccountDAOImpl method countUsers.
/**
* @param organizationName
* @param nameLike
* @return {@link Number}
* @throws GPDAOException
*/
@Override
public Number countUsers(String organizationName, String nameLike) throws GPDAOException {
checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Paramater organizationName must not be null or an Empty String.");
try {
CriteriaBuilder builder = super.criteriaBuilder();
CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
Root<GPUser> userRoot = builder.treat(root, GPUser.class);
criteriaQuery.select(builder.count(root));
List<Predicate> predicates = Lists.newArrayList();
predicates.add(builder.equal(root.join("organization").get("name"), organizationName));
predicates.add(builder.isNotNull(userRoot.get("username")));
if ((nameLike != null) && !(nameLike.isEmpty()))
predicates.add(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()));
criteriaQuery.where(predicates.stream().toArray(size -> new Predicate[size]));
return this.entityManager.createQuery(criteriaQuery).getSingleResult();
} catch (Exception ex) {
ex.printStackTrace();
throw new GPDAOException(ex);
}
}
use of org.geosdi.geoplatform.core.model.GPUser in project geo-platform by geosdi.
the class GPAccountDAOImpl method countAccounts.
/**
* @param nameLike
* @return {@link Number}
* @throws GPDAOException
*/
@Override
public Number countAccounts(String nameLike) throws GPDAOException {
checkArgument(((nameLike != null) && !(nameLike.trim().isEmpty())), "The Parameter nameLike must not be null or an empty string.");
try {
CriteriaBuilder builder = super.criteriaBuilder();
CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
Root<GPUser> userRoot = builder.treat(root, GPUser.class);
Root<GPApplication> applicationRoot = builder.treat(root, GPApplication.class);
criteriaQuery.select(builder.count(root));
criteriaQuery.where(builder.or(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()), builder.like(builder.lower(applicationRoot.get("appID")), nameLike.toLowerCase())));
return entityManager.createQuery(criteriaQuery).getSingleResult();
} catch (Exception ex) {
ex.printStackTrace();
throw new GPDAOException(ex);
}
}
Aggregations