use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class IntervalListType method createEntries.
@Override
@Transaction
public void createEntries(JsonObject metadata) {
if (!this.isValid()) {
throw new InvalidMasterListException();
}
if (metadata == null) {
List<ListTypeEntry> entries = this.getEntries();
if (entries.size() > 0) {
ListTypeEntry entry = entries.get(0);
ListTypeVersion working = entry.getWorking();
metadata = working.toJSON(false);
}
}
final JsonObject object = metadata;
this.getIntervals().forEach((pair) -> {
Date startDate = pair.getFirst();
this.getOrCreateEntry(startDate, object);
});
}
use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class ListType method getOrCreateEntry.
@Transaction
public ListTypeEntry getOrCreateEntry(Date forDate, JsonObject metadata) {
if (!this.isValid()) {
throw new InvalidMasterListException();
}
ListTypeEntryQuery query = new ListTypeEntryQuery(new QueryFactory());
query.WHERE(query.getListType().EQ(this));
query.AND(query.getForDate().EQ(forDate));
try (OIterator<? extends ListTypeEntry> it = query.getIterator()) {
if (it.hasNext()) {
return it.next();
}
}
return ListTypeEntry.create(this, forDate, metadata);
}
use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class ListType method delete.
@Override
@Transaction
public void delete() {
// Validate there are no public versions
ListTypeVersionQuery query = new ListTypeVersionQuery(new QueryFactory());
query.WHERE(query.getListType().EQ(this));
query.AND(query.getWorking().EQ(false));
query.AND(OR.get(query.getListVisibility().EQ(ListType.PUBLIC), query.getGeospatialVisibility().EQ(ListType.PUBLIC)));
long count = query.getCount();
if (count > 0) {
throw new CannotDeletePublicListTypeException();
}
// Delete all jobs
this.getJobs().forEach(job -> {
job.delete();
});
this.getEntries().forEach(entry -> {
entry.delete();
});
super.delete();
final File directory = this.getShapefileDirectory();
if (directory.exists()) {
try {
FileUtils.deleteDirectory(directory);
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
}
use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class ListTypeVersion method publishNoAuth.
@Transaction
public String publishNoAuth() {
this.lock();
try {
ListType masterlist = this.getListType();
if (!masterlist.isValid()) {
throw new InvalidMasterListException();
}
// Delete tile cache
ListTileCache.deleteTiles(this);
ListCurationHistory.deleteAll(this);
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
mdBusiness.deleteAllRecords();
MdAttributeConcreteDAO status = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("status");
if (status != null) {
ListTypeAttributeGroup.remove(status);
status.delete();
}
MdAttributeConcreteDAO statusDefaultLocale = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("statusDefaultLocale");
if (statusDefaultLocale != null) {
ListTypeAttributeGroup.remove(statusDefaultLocale);
statusDefaultLocale.delete();
}
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
// Add the type ancestor fields
Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
Collection<AttributeType> attributes = type.getAttributeMap().values();
Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
// ServerGeoObjectService service = new ServerGeoObjectService();
// ServerGeoObjectQuery query = service.createQuery(type,
// this.getPeriod());
Date forDate = this.getForDate();
BasicVertexRestriction restriction = masterlist.getRestriction(type, forDate);
BasicVertexQuery query = new BasicVertexQuery(type, forDate);
query.setRestriction(restriction);
Long count = query.getCount();
if (count == null) {
count = 0L;
}
long current = 0;
try {
ProgressService.put(this.getOid(), new Progress(0L, count, ""));
int pageSize = 1000;
long skip = 0;
while (skip < count) {
query = new BasicVertexQuery(type, forDate);
query.setRestriction(restriction);
query.setLimit(pageSize);
query.setSkip(skip);
// List<GeoObjectStatus> validStats = new
// ArrayList<GeoObjectStatus>();
// validStats.add(GeoObjectStatus.ACTIVE);
// validStats.add(GeoObjectStatus.INACTIVE);
// validStats.add(GeoObjectStatus.PENDING);
// validStats.add(GeoObjectStatus.NEW);
// query.setRestriction(new ServerStatusRestriction(validStats,
// this.getForDate(), JoinOp.OR));
List<ServerGeoObjectIF> results = query.getResults();
for (ServerGeoObjectIF result : results) {
Business business = new Business(mdBusiness.definesType());
publish(masterlist, type, result, business, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
Thread.yield();
ProgressService.put(this.getOid(), new Progress(current++, count, ""));
}
skip += pageSize;
}
this.setPublishDate(new Date());
this.apply();
return this.toJSON(true).toString();
} finally {
ProgressService.remove(this.getOid());
}
} finally {
this.unlock();
}
}
use of com.runwaysdk.dataaccess.transaction.Transaction in project geoprism-registry by terraframe.
the class MasterList method create.
@Transaction
public static MasterList create(JsonObject object) {
MasterList list = MasterList.fromJSON(object);
if (Session.getCurrentSession() != null && Session.getCurrentSession().getUser() != null) {
list.enforceActorHasPermission(Operation.CREATE);
}
if (list.getIsMaster() != null && list.getIsMaster()) {
Universal universal = list.getUniversal();
MasterListQuery query = new MasterListQuery(new QueryFactory());
query.WHERE(query.getUniversal().EQ(universal));
query.AND(query.getOrganization().EQ(list.getOrganization()));
query.AND(query.getIsMaster().EQ(true));
if (!list.isNew()) {
query.AND(query.getOid().NE(list.getOid()));
}
if (query.getCount() > 0) {
DuplicateMasterListException ex = new DuplicateMasterListException();
ex.setGeoObjectType(universal.getDisplayLabel().getValue());
throw ex;
}
}
list.apply();
return list;
}
Aggregations