use of org.geosdi.geoplatform.core.model.GPOrganization in project geo-platform by geosdi.
the class GPOrganizationDAOImpl method findByName.
/**
* @param name
* @return {@link GPOrganization}
* @throws GPDAOException
*/
@Override
public GPOrganization findByName(String name) throws GPDAOException {
checkArgument((name != null) && !(name.trim().isEmpty()), "The Parameter name must not be null or an empty string.");
try {
CriteriaBuilder builder = super.criteriaBuilder();
CriteriaQuery<GPOrganization> criteriaQuery = super.createCriteriaQuery();
Root<GPOrganization> root = criteriaQuery.from(this.persistentClass);
criteriaQuery.select(root);
criteriaQuery.where(builder.equal(root.get("name"), name));
List<GPOrganization> organizations = this.entityManager.createQuery(criteriaQuery).getResultList();
return ((organizations != null) && !(organizations.isEmpty()) ? organizations.get(0) : null);
} catch (Exception ex) {
ex.printStackTrace();
throw new GPDAOException(ex);
}
}
use of org.geosdi.geoplatform.core.model.GPOrganization in project geo-platform by geosdi.
the class GPServerDAOImpl method countServers.
/**
* @param organizationName
* @param type
* @param titleOrAliasName
* @return {@link Integer}
* @throws GPDAOException
*/
@Override
public Number countServers(String organizationName, GPCapabilityType type, String titleOrAliasName) throws GPDAOException {
checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Parameter organizationName must not ne null or an empty string.");
checkArgument(type != null, "The Parameter type must not ne null.");
try {
CriteriaBuilder builder = super.criteriaBuilder();
CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
Root<GeoPlatformServer> root = criteriaQuery.from(this.persistentClass);
List<Predicate> predicates = Lists.newArrayList();
if ((titleOrAliasName != null) && !(titleOrAliasName.trim().isEmpty())) {
predicates.add(builder.or(builder.like(builder.lower(root.get("title")), titleOrAliasName.toLowerCase()), builder.like(builder.lower(root.get("aliasName")), titleOrAliasName.toLowerCase())));
}
Join<GeoPlatformServer, GPOrganization> join = root.join("organization");
predicates.add(builder.equal(join.get("name"), organizationName));
predicates.add(builder.equal(root.get("serverType"), type));
criteriaQuery.select(builder.count(root));
criteriaQuery.where(predicates.stream().toArray(Predicate[]::new));
return this.entityManager.createQuery(criteriaQuery).getSingleResult();
} catch (Exception ex) {
ex.printStackTrace();
throw new GPDAOException(ex);
}
}
use of org.geosdi.geoplatform.core.model.GPOrganization in project geo-platform by geosdi.
the class CSWServiceDelegate method saveServerCSW.
/**
* @see {@link GeoPlatformCSWService#saveServerCSW(String, String, String)},
* java.lang.String)
*/
@Override
public ServerCSWDTO saveServerCSW(String alias, String serverUrl, String organization) throws IllegalParameterFault {
serverUrl = this.deleteQueryStringFromURL(serverUrl);
GeoPlatformServer server = serverDao.findByServerUrl(serverUrl);
if (server != null) {
// If there is already a server with the specified URLs
return new ServerCSWDTO(server);
}
GPOrganization org = organizationDao.findByName(organization);
if (org == null) {
throw new IllegalParameterFault("CSW Server to save have an organization that does not exist");
}
try {
CatalogCapabilities capabilities = catalogCapabilitiesBean.bindUrl(serverUrl);
server = new GeoPlatformServer();
server.setServerType(GPCapabilityType.CSW);
server.setServerUrl(serverUrl);
server.setAliasName(alias);
server.setOrganization(org);
server.setTitle(capabilities.getServiceIdentification().getTitle());
server.setAbstractServer(capabilities.getServiceIdentification().getAbstractText());
server.setName(capabilities.getServiceProvider().getProviderName());
// TODO assert
CSWEntityCorrectness.checkCSWServer(server);
serverDao.persist(server);
} catch (Exception ex) {
logger.error("### MalformedURLException: {}", ex.getMessage());
throw new IllegalParameterFault("Exception : " + ex.getMessage());
}
return new ServerCSWDTO(server);
}
use of org.geosdi.geoplatform.core.model.GPOrganization in project geo-platform by geosdi.
the class GPOrganizationDelegate method deleteOrganization.
@Override
public Boolean deleteOrganization(Long organizationID) throws ResourceNotFoundFault {
GPOrganization organization = organizationDao.find(organizationID);
if (organization == null) {
throw new ResourceNotFoundFault("Organization not found", organizationID);
}
// TODO assert
EntityCorrectness.checkOrganizationLog(organization);
return organizationDao.removeById(organization.getId());
}
use of org.geosdi.geoplatform.core.model.GPOrganization in project geo-platform by geosdi.
the class GPServerDelegate method saveServer.
@Override
public ServerDTO saveServer(WSSaveServerRequest saveServerReq) throws IllegalParameterFault {
if (saveServerReq == null) {
throw new IllegalParameterFault("The WSSaveServerRequest must " + "not be null.");
}
Long id = saveServerReq.getId();
String serverUrl = saveServerReq.getServerUrl();
String organization = saveServerReq.getOrganization();
String aliasServerName = saveServerReq.getAliasServerName();
try {
URL serverURL = new URL(serverUrl);
} catch (MalformedURLException e) {
logger.error("MalformedURLException: " + e);
throw new IllegalParameterFault("Malformed URL");
}
GPOrganization org = organizationDao.findByName(organization);
if (org == null) {
throw new IllegalParameterFault("Server to save have an organization that does not exist");
}
GeoPlatformServer server;
if (id != null) {
// Existent server
server = serverDao.find(id);
} else {
// New server
if (this.isURLServerAlreadyExists(serverUrl)) {
throw new IllegalParameterFault("Duplicated Server URL");
}
server = new GeoPlatformServer();
server.setServerType(WMS);
}
server.setAliasName(aliasServerName);
server.setServerUrl(serverUrl);
server.setAuthServer(new GPAuthServer(saveServerReq.getUsername(), saveServerReq.getPassword()));
server.setProxy(saveServerReq.isProxy());
server.setOrganization(org);
serverDao.persist(server);
return new ServerDTO(server);
}
Aggregations