use of gov.usgs.cida.coastalhazards.model.util.DataDomain in project coastal-hazards by USGS-CIDA.
the class DataDomainManager method load.
public DataDomain load(String id) {
DataDomain domain = null;
Query selectQuery = em.createQuery(HQL_SELECT_BY_ID);
selectQuery.setParameter("id", id);
List<DataDomain> resultList = selectQuery.getResultList();
if (!resultList.isEmpty()) {
domain = resultList.get(0);
}
return domain;
}
use of gov.usgs.cida.coastalhazards.model.util.DataDomain in project coastal-hazards by USGS-CIDA.
the class DataDomainManager method regenerateDomainForItem.
/**
* Delete the data domain associated with the given item and then rebuild
* it from the WFS.
* @param item The item to delete the associated data domain for
* @return Boolean Representing whether or not the delete executed successfully.
*/
public boolean regenerateDomainForItem(Item item) {
boolean didRegen = false;
if (item == null) {
throw new IllegalArgumentException("Item must be valid data item");
}
if (deleteDomainForItem(item)) {
log.debug("Domain deleted. Regenerating...");
SortedSet<String> domainVals = DataDomainUtility.retrieveDomainFromWFS(item);
SortedSet<String> domainAsYears = DataDomainUtility.getDomainAsYears(domainVals);
DataDomain domain = new DataDomain();
domain.setItemId(item.getId());
domain.setDomainValues(domainAsYears);
save(domain);
didRegen = true;
}
return didRegen;
}
use of gov.usgs.cida.coastalhazards.model.util.DataDomain in project coastal-hazards by USGS-CIDA.
the class DataDomainManager method isPersisted.
public boolean isPersisted(String id) {
boolean isPersisted = false;
Query selectQuery = em.createQuery(HQL_SELECT_BY_ID);
selectQuery.setParameter("id", id);
List<DataDomain> resultList = selectQuery.getResultList();
if (!resultList.isEmpty()) {
isPersisted = true;
}
return isPersisted;
}
use of gov.usgs.cida.coastalhazards.model.util.DataDomain in project coastal-hazards by USGS-CIDA.
the class DataDomainManager method getDomainForItem.
/**
* Grab the domain of the item data and store it for later
* TODO if Item has been modified, invalidate DB persisted entity
* @param item Item for which domain to gather
* @return DataDomain object making up the domain
*/
public DataDomain getDomainForItem(Item item) {
DataDomain domain = new DataDomain();
if (item == null) {
throw new IllegalArgumentException("Item must be valid data item");
}
Lock domainLock = getOrCreateLock(item.getId());
try {
domainLock.lock();
if (isPersisted(item.getId())) {
log.debug("Found domain in database, return it");
domain = load(item.getId());
} else {
log.debug("No domain found in database, get it from WFS");
SortedSet<String> domainVals = DataDomainUtility.retrieveDomainFromWFS(item);
// only using this for years for now, separated out for future endeavors though
SortedSet<String> domainAsYears = DataDomainUtility.getDomainAsYears(domainVals);
domain.setItemId(item.getId());
domain.setDomainValues(domainAsYears);
save(domain);
}
} finally {
domainLock.unlock();
}
return domain;
}
use of gov.usgs.cida.coastalhazards.model.util.DataDomain in project coastal-hazards by USGS-CIDA.
the class DataDomainResource method getDataDomain.
@GET
@Path("/item/{id}")
public Response getDataDomain(@PathParam("id") String id, @Context Request request) {
Response response = null;
try (ItemManager itemManager = new ItemManager();
DataDomainManager domainManager = new DataDomainManager()) {
Item item = itemManager.load(id);
if (item == null || item.getType() != Item.Type.historical) {
throw new NotFoundException("Only historical is supported at this time");
}
DataDomain domain = domainManager.getDomainForItem(item);
Response checkModified = HTTPCachingUtil.checkModified(request, domain);
if (checkModified != null) {
response = checkModified;
} else {
Gson serializer = GsonUtil.getDefault();
String domainJson = serializer.toJson(domain);
response = Response.ok(domainJson, MediaType.APPLICATION_JSON_TYPE).lastModified(domain.getLastModified()).build();
}
}
return response;
}
Aggregations