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);
}
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations