Search in sources :

Example 36 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class MasterList method fromJSON.

public static MasterList fromJSON(JsonObject object) {
    try {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String typeCode = object.get(MasterList.TYPE_CODE).getAsString();
        ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
        LocalizedValue label = LocalizedValue.fromJSON(object.get(MasterList.DISPLAYLABEL).getAsJsonObject());
        MasterList list = null;
        if (object.has("oid") && !object.get("oid").isJsonNull()) {
            String oid = object.get("oid").getAsString();
            list = MasterList.lock(oid);
        } else {
            list = new MasterList();
        }
        list.setUniversal(type.getUniversal());
        LocalizedValueConverter.populate(list.getDisplayLabel(), label);
        list.setCode(object.get(MasterList.CODE).getAsString());
        list.getDescriptionLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.DESCRIPTIONLOCAL).getAsJsonObject()).getLocaleMap());
        list.getProcessLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.PROCESSLOCAL).getAsJsonObject()).getLocaleMap());
        list.getProgressLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.PROGRESSLOCAL).getAsJsonObject()).getLocaleMap());
        list.getAccessConstraintsLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.ACCESSCONSTRAINTSLOCAL).getAsJsonObject()).getLocaleMap());
        list.getUseConstraintsLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.USECONSTRAINTSLOCAL).getAsJsonObject()).getLocaleMap());
        list.getAcknowledgementsLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.ACKNOWLEDGEMENTSLOCAL).getAsJsonObject()).getLocaleMap());
        list.getDisclaimerLocal().setLocaleMap(LocalizedValue.fromJSON(object.get(MasterList.DISCLAIMERLOCAL).getAsJsonObject()).getLocaleMap());
        list.setContactName(object.get(MasterList.CONTACTNAME).getAsString());
        list.setTelephoneNumber(object.get(MasterList.TELEPHONENUMBER).getAsString());
        list.setEmail(object.get(MasterList.EMAIL).getAsString());
        list.setHierarchies(object.get(MasterList.HIERARCHIES).getAsJsonArray().toString());
        list.setOrganizationId(object.get(MasterList.ORGANIZATION).getAsString());
        if (object.has(MasterList.SUBTYPEHIERARCHIES) && !object.get(MasterList.SUBTYPEHIERARCHIES).isJsonNull()) {
            list.setSubtypeHierarchies(object.get(MasterList.SUBTYPEHIERARCHIES).getAsJsonArray().toString());
        }
        if (object.has(MasterList.ISMASTER) && !object.get(MasterList.ISMASTER).isJsonNull()) {
            list.setIsMaster(object.get(MasterList.ISMASTER).getAsBoolean());
        }
        if (object.has(MasterList.VISIBILITY) && !object.get(MasterList.VISIBILITY).isJsonNull()) {
            list.setVisibility(object.get(MasterList.VISIBILITY).getAsString());
        }
        if (object.has(MasterList.FREQUENCY) && !object.get(MasterList.FREQUENCY).isJsonNull()) {
            final String frequency = object.get(MasterList.FREQUENCY).getAsString();
            final boolean same = list.getFrequency().stream().anyMatch(f -> {
                return f.name().equals(frequency);
            });
            if (!same) {
                list.clearFrequency();
                list.addFrequency(ChangeFrequency.valueOf(frequency));
            }
        }
        if (object.has(MasterList.PUBLISHINGSTARTDATE)) {
            if (!object.get(MasterList.PUBLISHINGSTARTDATE).isJsonNull()) {
                String date = object.get(MasterList.PUBLISHINGSTARTDATE).getAsString();
                if (date.length() > 0) {
                    list.setPublishingStartDate(format.parse(date));
                } else {
                    list.setPublishingStartDate(null);
                }
            } else {
                list.setPublishingStartDate(null);
            }
        }
        if (object.has(MasterList.REPRESENTATIVITYDATE)) {
            if (!object.get(MasterList.REPRESENTATIVITYDATE).isJsonNull()) {
                String date = object.get(MasterList.REPRESENTATIVITYDATE).getAsString();
                if (date.length() > 0) {
                    list.setRepresentativityDate(format.parse(date));
                } else {
                    list.setRepresentativityDate(null);
                }
            } else {
                list.setRepresentativityDate(null);
            }
        }
        if (object.has(MasterList.PUBLISHDATE)) {
            if (!object.get(MasterList.PUBLISHDATE).isJsonNull()) {
                String date = object.get(MasterList.PUBLISHDATE).getAsString();
                if (date.length() > 0) {
                    list.setPublishDate(format.parse(date));
                } else {
                    list.setPublishDate(null);
                }
            } else {
                list.setPublishDate(null);
            }
        }
        return list;
    } catch (ParseException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 37 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class MasterList method delete.

@Override
@Transaction
public void delete() {
    // Delete all jobs
    List<MasterListJob> jobs = this.getJobs();
    for (MasterListJob job : jobs) {
        job.delete();
    }
    List<MasterListVersion> versions = this.getVersions(null);
    for (MasterListVersion version : versions) {
        version.delete();
    }
    super.delete();
    final File directory = this.getShapefileDirectory();
    if (directory.exists()) {
        try {
            FileUtils.deleteDirectory(directory);
        } catch (IOException e) {
            throw new ProgrammingErrorException(e);
        }
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MasterListJob(net.geoprism.registry.etl.MasterListJob) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 38 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class MasterListVersion method buildQueryConditionsFromFilter.

private Map<MdAttributeConcreteDAOIF, Condition> buildQueryConditionsFromFilter(String filterJson, String ignoreAttribute, ComponentQuery query, MdBusinessDAOIF mdBusiness) {
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = new HashMap<MdAttributeConcreteDAOIF, Condition>();
    if (filterJson != null && filterJson.length() > 0) {
        DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
        for (int i = 0; i < filters.size(); i++) {
            JsonObject filter = filters.get(i).getAsJsonObject();
            String attribute = filter.get("attribute").getAsString();
            if (ignoreAttribute == null || !attribute.equals(ignoreAttribute)) {
                MdAttributeConcreteDAOIF mdAttr = mdBusiness.definesAttribute(attribute);
                BasicCondition condition = null;
                if (mdAttr instanceof MdAttributeMomentDAOIF) {
                    JsonObject jObject = filter.get("value").getAsJsonObject();
                    try {
                        if (jObject.has("start") && !jObject.get("start").isJsonNull()) {
                            String date = jObject.get("start").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).GE(filterFormat.parse(date));
                            }
                        }
                        if (jObject.has("end") && !jObject.get("end").isJsonNull()) {
                            String date = jObject.get("end").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).LE(filterFormat.parse(date));
                            }
                        }
                    } catch (ParseException e) {
                        throw new ProgrammingErrorException(e);
                    }
                } else if (mdAttr instanceof MdAttributeBooleanDAOIF) {
                    String value = filter.get("value").getAsString();
                    Boolean bVal = Boolean.valueOf(value);
                    condition = ((AttributeBoolean) query.get(attribute)).EQ(bVal);
                } else {
                    String value = filter.get("value").getAsString();
                    condition = query.get(attribute).EQ(value);
                }
                if (condition != null) {
                    if (conditionMap.containsKey(mdAttr)) {
                        conditionMap.put(mdAttr, conditionMap.get(mdAttr).OR(condition));
                    } else {
                        conditionMap.put(mdAttr, condition);
                    }
                }
            }
        }
    }
    return conditionMap;
}
Also used : Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ParseException(java.text.ParseException) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 39 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class MasterListVersion method generateShapefile.

public File generateShapefile() {
    String filename = this.getOid() + ".zip";
    final MasterList list = this.getMasterlist();
    final File directory = list.getShapefileDirectory();
    directory.mkdirs();
    final File file = new File(directory, filename);
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.isValid(mdAttribute)).collect(Collectors.toList());
    try {
        MasterListShapefileExporter exporter = new MasterListShapefileExporter(this, mdBusiness, mdAttributes, null);
        try (final InputStream istream = exporter.export()) {
            try (final FileOutputStream fos = new FileOutputStream(file)) {
                IOUtils.copy(istream, fos);
            }
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
    return file;
}
Also used : MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) Authenticate(com.runwaysdk.business.rbac.Authenticate) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) JSONException(org.json.JSONException) Condition(com.runwaysdk.query.Condition) IndexTypes(com.runwaysdk.constants.IndexTypes) GeoJSONWriter(org.wololo.jts2geojson.GeoJSONWriter) TableMetadata(net.geoprism.registry.masterlist.TableMetadata) Map(java.util.Map) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ComponentIF(com.runwaysdk.ComponentIF) ListTypeAttributeComparator(net.geoprism.registry.masterlist.ListTypeAttributeComparator) Set(java.util.Set) BusinessFacade(com.runwaysdk.business.BusinessFacade) IOUtils(org.apache.commons.io.IOUtils) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) JsonArray(com.google.gson.JsonArray) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) GeoserverRemoveWMSCommand(net.geoprism.registry.command.GeoserverRemoveWMSCommand) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) VertexObject(com.runwaysdk.business.graph.VertexObject) SimpleDateFormat(java.text.SimpleDateFormat) ExecutableJob(com.runwaysdk.system.scheduler.ExecutableJob) JsonParser(com.google.gson.JsonParser) DefaultConfiguration(net.geoprism.DefaultConfiguration) NumberFormat(java.text.NumberFormat) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) ServerParentTreeNode(net.geoprism.registry.model.ServerParentTreeNode) Calendar(java.util.Calendar) QueryFactory(com.runwaysdk.query.QueryFactory) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) VertexGeoObjectQuery(net.geoprism.registry.query.graph.VertexGeoObjectQuery) ComponentQuery(com.runwaysdk.query.ComponentQuery) MdAttribute(com.runwaysdk.system.metadata.MdAttribute) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) Business(com.runwaysdk.business.Business) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MasterListShapefileExporter(net.geoprism.registry.shapefile.MasterListShapefileExporter) BusinessInfo(com.runwaysdk.constants.BusinessInfo) MdAttributePolygon(com.runwaysdk.system.gis.metadata.MdAttributePolygon) JsonObject(com.google.gson.JsonObject) Operation(com.runwaysdk.business.rbac.Operation) Date(java.util.Date) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) ValueObject(com.runwaysdk.dataaccess.ValueObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributeBooleanInfo(com.runwaysdk.constants.MdAttributeBooleanInfo) PublishMasterListVersionJobQuery(net.geoprism.registry.etl.PublishMasterListVersionJobQuery) MdTableInfo(com.runwaysdk.constants.MdTableInfo) ValueQuery(com.runwaysdk.query.ValueQuery) MdAttributeShape(com.runwaysdk.system.gis.metadata.MdAttributeShape) Locale(java.util.Locale) Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(java.text.ParseException) AttributeCharacterType(org.commongeoregistry.adapter.metadata.AttributeCharacterType) Database(com.runwaysdk.dataaccess.database.Database) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) DateFormat(java.text.DateFormat) GeoserverFacade(net.geoprism.gis.geoserver.GeoserverFacade) BusinessQuery(com.runwaysdk.business.BusinessQuery) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) LocationInfo(net.geoprism.registry.model.LocationInfo) Collection(java.util.Collection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) MdAttributeConcreteInfo(com.runwaysdk.constants.MdAttributeConcreteInfo) Collectors(java.util.stream.Collectors) ProgressService(net.geoprism.registry.progress.ProgressService) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) MdAttributeDoubleInfo(com.runwaysdk.constants.MdAttributeDoubleInfo) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) MdAttributeMultiPolygon(com.runwaysdk.system.gis.metadata.MdAttributeMultiPolygon) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Entry(java.util.Map.Entry) MdClassificationDAO(com.runwaysdk.dataaccess.metadata.graph.MdClassificationDAO) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) GeometryType(org.commongeoregistry.adapter.constants.GeometryType) MdAttributeIndices(com.runwaysdk.system.metadata.MdAttributeIndices) AbstractClassification(com.runwaysdk.system.AbstractClassification) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) PublishMasterListVersionJob(net.geoprism.registry.etl.PublishMasterListVersionJob) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) HashMap(java.util.HashMap) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeLocalInfo(com.runwaysdk.constants.MdAttributeLocalInfo) Progress(net.geoprism.registry.progress.Progress) ServiceFactory(net.geoprism.registry.service.ServiceFactory) Classifier(net.geoprism.ontology.Classifier) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) PublishShapefileJob(net.geoprism.registry.etl.PublishShapefileJob) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeCharacterInfo(com.runwaysdk.constants.MdAttributeCharacterInfo) GeoserverCreateWMSCommand(net.geoprism.registry.command.GeoserverCreateWMSCommand) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) MdAttributeUUIDDAO(com.runwaysdk.dataaccess.metadata.MdAttributeUUIDDAO) LinkedList(java.util.LinkedList) MdAttributeGeometry(com.runwaysdk.system.gis.metadata.MdAttributeGeometry) MdAttributeDateTime(com.runwaysdk.system.metadata.MdAttributeDateTime) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdAttributeConcreteDAO(com.runwaysdk.dataaccess.metadata.MdAttributeConcreteDAO) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) FileInputStream(java.io.FileInputStream) AttributeIntegerType(org.commongeoregistry.adapter.metadata.AttributeIntegerType) OIterator(com.runwaysdk.query.OIterator) PublishShapefileJobQuery(net.geoprism.registry.etl.PublishShapefileJobQuery) Session(com.runwaysdk.session.Session) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) Collections(java.util.Collections) JSONArray(org.json.JSONArray) InputStream(java.io.InputStream) MasterListShapefileExporter(net.geoprism.registry.shapefile.MasterListShapefileExporter) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) IOException(java.io.IOException) File(java.io.File) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 40 with ProgrammingErrorException

use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.

the class MasterListVersion method bbox.

public String bbox() {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
    double[] geometry = GeoserverFacade.getBBOX(mdBusiness.getTableName());
    if (geometry != null) {
        try {
            JSONArray bboxArr = new JSONArray();
            bboxArr.put(geometry[0]);
            bboxArr.put(geometry[1]);
            bboxArr.put(geometry[2]);
            bboxArr.put(geometry[3]);
            return bboxArr.toString();
        } catch (JSONException ex) {
            throw new ProgrammingErrorException(ex);
        }
    }
    return null;
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Aggregations

ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)67 IOException (java.io.IOException)34 SimpleDateFormat (java.text.SimpleDateFormat)21 JsonObject (com.google.gson.JsonObject)18 File (java.io.File)16 ParseException (java.text.ParseException)16 InputStream (java.io.InputStream)13 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)13 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)12 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)11 JSONException (org.json.JSONException)11 JsonArray (com.google.gson.JsonArray)10 List (java.util.List)10 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)8