Search in sources :

Example 1 with Progress

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;
}
Also used : JsonArray(com.google.gson.JsonArray) Progress(net.geoprism.registry.progress.Progress) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) CurationService(net.geoprism.registry.curation.CurationService) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 2 with Progress

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();
    }
}
Also used : Locale(java.util.Locale) MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Progress(net.geoprism.registry.progress.Progress) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Date(java.util.Date) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) Point(com.vividsolutions.jts.geom.Point) BasicVertexRestriction(net.geoprism.registry.query.graph.BasicVertexRestriction) BasicVertexQuery(net.geoprism.registry.query.graph.BasicVertexQuery) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) List(java.util.List) LinkedList(java.util.LinkedList) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with Progress

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;
}
Also used : JsonArray(com.google.gson.JsonArray) Progress(net.geoprism.registry.progress.Progress) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 4 with Progress

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();
    }
}
Also used : Locale(java.util.Locale) MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Progress(net.geoprism.registry.progress.Progress) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) Date(java.util.Date) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) VertexGeoObjectQuery(net.geoprism.registry.query.graph.VertexGeoObjectQuery) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) List(java.util.List) LinkedList(java.util.LinkedList) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 5 with Progress

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());
    }
}
Also used : Progress(net.geoprism.registry.progress.Progress) OnOpen(javax.websocket.OnOpen)

Aggregations

Progress (net.geoprism.registry.progress.Progress)5 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Business (com.runwaysdk.business.Business)2 MdAttributeConcreteDAO (com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO)2 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)2 MdAttributeMultiPoint (com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint)2 MdAttributePoint (com.runwaysdk.system.gis.metadata.MdAttributePoint)2 MdAttributeLong (com.runwaysdk.system.metadata.MdAttributeLong)2 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)2 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Locale (java.util.Locale)2