use of net.geoprism.registry.progress.Progress in project geoprism-registry by terraframe.
the class ListTypeVersion method toJSON.
public JsonObject toJSON(boolean includeAttribute) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
String filename = this.getOid() + ".zip";
ListType masterlist = this.getListType();
final File directory = masterlist.getShapefileDirectory();
final File file = new File(directory, filename);
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
boolean isMember = Organization.isMember(masterlist.getOrganization());
JsonObject object = new JsonObject();
if (this.isAppliedToDB()) {
object.addProperty(ListTypeVersion.OID, this.getOid());
}
object.addProperty(ListType.DISPLAYLABEL, masterlist.getDisplayLabel().getValue());
object.addProperty(ListTypeVersion.TYPE_CODE, type.getCode());
object.addProperty(ListTypeVersion.ORG_CODE, type.getOrganization().getCode());
object.addProperty(ListTypeVersion.LISTTYPE, masterlist.getOid());
object.addProperty(ListTypeVersion.FORDATE, format.format(this.getForDate()));
object.addProperty(ListTypeVersion.CREATEDATE, format.format(this.getCreateDate()));
object.addProperty(ListTypeVersion.VERSIONNUMBER, this.getVersionNumber());
object.addProperty(ListTypeVersion.WORKING, this.getWorking());
object.addProperty("isGeometryEditable", type.isGeometryEditable());
object.addProperty("isAbstract", type.getIsAbstract());
object.addProperty("shapefile", file.exists());
object.addProperty("isMember", isMember);
object.add(ListTypeVersion.PERIOD, masterlist.formatVersionLabel(this));
object.add(ListType.LIST_METADATA, this.toMetadataJSON("list"));
object.add(ListType.GEOSPATIAL_METADATA, this.toMetadataJSON("geospatial"));
Progress progress = ProgressService.get(this.getOid());
if (progress != null) {
object.add("refreshProgress", progress.toJson());
}
if (type.getSuperType() != null) {
object.addProperty("superTypeCode", type.getSuperType().getCode());
}
if (type.getIsAbstract()) {
JsonArray subtypes = new JsonArray();
for (ServerGeoObjectType subtype : type.getSubtypes()) {
JsonObject jo = new JsonObject();
jo.addProperty("code", subtype.getCode());
jo.addProperty("label", subtype.getLabel().getValue());
subtypes.add(jo);
}
object.add("subtypes", subtypes);
}
if (this.getPublishDate() != null) {
object.addProperty(ListTypeVersion.PUBLISHDATE, format.format(this.getPublishDate()));
}
if (includeAttribute) {
object.add(ListTypeVersion.ATTRIBUTES, this.getAttributesAsJson());
}
if (this.getWorking() && masterlist.doesActorHaveWritePermission()) {
object.add("curation", new CurationService().getListCurationInfo(this));
} else {
object.add("curation", new JsonObject());
}
return object;
}
use of net.geoprism.registry.progress.Progress 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 net.geoprism.registry.progress.Progress in project geoprism-registry by terraframe.
the class MasterListVersion method toJSON.
public JsonObject toJSON(boolean includeAttribute) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
String filename = this.getOid() + ".zip";
MasterList masterlist = this.getMasterlist();
final File directory = masterlist.getShapefileDirectory();
final File file = new File(directory, filename);
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
JsonObject object = new JsonObject();
if (this.isAppliedToDB()) {
object.addProperty(MasterListVersion.OID, this.getOid());
}
object.addProperty(MasterList.DISPLAYLABEL, masterlist.getDisplayLabel().getValue());
object.addProperty(MasterListVersion.TYPE_CODE, type.getCode());
object.addProperty(MasterListVersion.ORG_CODE, type.getOrganization().getCode());
object.addProperty(MasterListVersion.MASTERLIST, masterlist.getOid());
object.addProperty(MasterListVersion.FORDATE, format.format(this.getForDate()));
object.addProperty(MasterListVersion.CREATEDATE, format.format(this.getCreateDate()));
object.addProperty(MasterListVersion.PERIOD, this.getPeriod(masterlist, format));
object.addProperty("isGeometryEditable", type.isGeometryEditable());
object.addProperty("isAbstract", type.getIsAbstract());
object.addProperty("shapefile", file.exists());
Progress progress = ProgressService.get(this.getOid());
if (progress != null) {
object.add("refreshProgress", progress.toJson());
}
if (type.getSuperType() != null) {
object.addProperty("superTypeCode", type.getSuperType().getCode());
}
if (type.getIsAbstract()) {
JsonArray subtypes = new JsonArray();
for (ServerGeoObjectType subtype : type.getSubtypes()) {
JsonObject jo = new JsonObject();
jo.addProperty("code", subtype.getCode());
jo.addProperty("label", subtype.getLabel().getValue());
subtypes.add(jo);
}
object.add("subtypes", subtypes);
}
if (this.getPublishDate() != null) {
object.addProperty(MasterListVersion.PUBLISHDATE, format.format(this.getPublishDate()));
}
if (includeAttribute) {
object.add(MasterListVersion.ATTRIBUTES, this.getAttributesAsJson());
}
return object;
}
use of net.geoprism.registry.progress.Progress in project geoprism-registry by terraframe.
the class MasterListVersion method publishNoAuth.
@Transaction
public String publishNoAuth() {
this.lock();
try {
MasterList masterlist = this.getMasterlist();
if (!masterlist.isValid()) {
throw new InvalidMasterListException();
}
// Delete tile cache
TileCache.deleteTiles(this);
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
mdBusiness.deleteAllRecords();
MdAttributeConcreteDAO status = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("status");
if (status != null) {
MasterListAttributeGroup.remove(status);
status.delete();
}
MdAttributeConcreteDAO statusDefaultLocale = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("statusDefaultLocale");
if (statusDefaultLocale != null) {
MasterListAttributeGroup.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());
VertexGeoObjectQuery query = new VertexGeoObjectQuery(type, this.getForDate());
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 VertexGeoObjectQuery(type, this.getForDate());
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(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 net.geoprism.registry.progress.Progress in project geoprism-registry by terraframe.
the class ProgressEndpoint method onOpen.
@OnOpen
public void onOpen(Session session, EndpointConfig config, @PathParam("key") String key) throws IOException {
this.session = session;
this.key = key;
endpoints.add(this);
// If the key is already in progress then update the client immediately
Progress progress = ProgressService.get(key);
if (progress != null) {
this.session.getBasicRemote().sendText(progress.toJson().toString());
}
}
Aggregations