use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class Transition method validate.
public void validate(TransitionEvent event, VertexServerGeoObject source, VertexServerGeoObject target) {
ServerGeoObjectType beforeType = ServerGeoObjectType.get(event.getBeforeTypeCode());
ServerGeoObjectType afterType = ServerGeoObjectType.get(event.getAfterTypeCode());
List<ServerGeoObjectType> beforeSubtypes = beforeType.getSubtypes();
List<ServerGeoObjectType> afterSubtypes = afterType.getSubtypes();
if (!(beforeSubtypes.contains(source.getType()) || beforeType.getCode().equals(source.getType().getCode()))) {
// This should be prevented by the front-end
throw new ProgrammingErrorException("Source type must be a subtype of (" + beforeType.getCode() + ")");
}
if (!(afterSubtypes.contains(target.getType()) || afterType.getCode().equals(target.getType().getCode()))) {
// This should be prevented by the front-end
throw new ProgrammingErrorException("Target type must be a subtype of (" + afterType.getCode() + ")");
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class TransitionEvent method apply.
@Transaction
public static JsonObject apply(JsonObject json) {
try {
String beforeTypeCode = json.get(TransitionEvent.BEFORETYPECODE).getAsString();
String afterTypeCode = json.get(TransitionEvent.AFTERTYPECODE).getAsString();
ServerGeoObjectType beforeType = ServerGeoObjectType.get(beforeTypeCode);
ServerGeoObjectType afterType = ServerGeoObjectType.get(afterTypeCode);
ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(beforeType.getOrganization().getCode(), beforeType);
// ServiceFactory.getGeoObjectPermissionService().enforceCanWrite(afterType.getOrganization().getCode(),
// afterType);
DateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
LocalizedValue description = LocalizedValue.fromJSON(json.get(TransitionEvent.DESCRIPTION).getAsJsonObject());
TransitionEvent event = json.has(OID) ? TransitionEvent.get(json.get(OID).getAsString()) : new TransitionEvent();
LocalizedValueConverter.populate(event, TransitionEvent.DESCRIPTION, description);
event.setEventDate(format.parse(json.get(TransitionEvent.EVENTDATE).getAsString()));
event.setBeforeTypeCode(beforeTypeCode);
event.setAfterTypeCode(afterTypeCode);
event.setBeforeTypeOrgCode(beforeType.getOrganization().getCode());
event.setAfterTypeOrgCode(afterType.getOrganization().getCode());
event.apply();
JsonArray transitions = json.get("transitions").getAsJsonArray();
List<String> appliedTrans = new ArrayList<String>();
for (int i = 0; i < transitions.size(); i++) {
JsonObject object = transitions.get(i).getAsJsonObject();
Transition trans = Transition.apply(event, i, object);
appliedTrans.add(trans.getOid());
}
for (Transition trans : event.getTransitions()) {
if (!appliedTrans.contains(trans.getOid())) {
trans.delete();
}
}
return event.toJSON(false);
} catch (ParseException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class TransitionEvent method addPageWhereCriteria.
public static void addPageWhereCriteria(StringBuilder statement, Map<String, Object> parameters, String attrConditions) {
List<String> whereConditions = new ArrayList<String>();
// Add permissions criteria
if (Session.getCurrentSession() != null) {
String beforeCondition = GeoObjectTypeRestrictionUtil.buildTypeWritePermissionsFilter(TransitionEvent.BEFORETYPEORGCODE, TransitionEvent.BEFORETYPECODE);
if (beforeCondition.length() > 0) {
whereConditions.add(beforeCondition);
}
String afterCondition = GeoObjectTypeRestrictionUtil.buildTypeReadPermissionsFilter(TransitionEvent.AFTERTYPEORGCODE, TransitionEvent.AFTERTYPECODE);
if (afterCondition.length() > 0) {
whereConditions.add(afterCondition);
}
}
// Filter based on attributes
if (attrConditions != null && attrConditions.length() > 0) {
List<String> lAttrConditions = new ArrayList<String>();
JsonArray jaAttrConditions = JsonParser.parseString(attrConditions).getAsJsonArray();
for (int i = 0; i < jaAttrConditions.size(); ++i) {
JsonObject attrCondition = jaAttrConditions.get(i).getAsJsonObject();
String attr = attrCondition.get("attribute").getAsString();
MdVertexDAO eventMd = (MdVertexDAO) MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
MdAttributeDAOIF mdAttr = eventMd.definesAttribute(attr);
if (attr.equals(TransitionEvent.EVENTDATE)) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
List<String> dateConditions = new ArrayList<String>();
try {
if (attrCondition.has("startDate") && !attrCondition.get("startDate").isJsonNull() && attrCondition.get("startDate").getAsString().length() > 0) {
Date startDate = format.parse(attrCondition.get("startDate").getAsString());
dateConditions.add(mdAttr.getColumnName() + ">=:startDate" + i);
parameters.put("startDate" + i, startDate);
}
if (attrCondition.has("endDate") && !attrCondition.get("endDate").isJsonNull() && attrCondition.get("endDate").getAsString().length() > 0) {
Date endDate = format.parse(attrCondition.get("endDate").getAsString());
dateConditions.add(mdAttr.getColumnName() + "<=:endDate" + i);
parameters.put("endDate" + i, endDate);
}
} catch (ParseException e) {
throw new ProgrammingErrorException(e);
}
if (dateConditions.size() > 0) {
lAttrConditions.add("(" + StringUtils.join(dateConditions, " AND ") + ")");
}
} else if (attrCondition.has("value") && !attrCondition.get("value").isJsonNull() && attrCondition.get("value").getAsString().length() > 0) {
String value = attrCondition.get("value").getAsString();
lAttrConditions.add(mdAttr.getColumnName() + "=:val" + i);
parameters.put("val" + i, value);
}
}
if (lAttrConditions.size() > 0) {
whereConditions.add(StringUtils.join(lAttrConditions, " AND "));
}
}
if (whereConditions.size() > 0) {
statement.append(" WHERE " + StringUtils.join(whereConditions, " AND "));
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class RegistryJsonTimeFormatter method read.
@Override
public Date read(JsonReader in) throws IOException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
try {
return sdf.parse(in.nextString());
} catch (ParseException | IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class AttributeTypeConverter method build.
public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
Locale locale = Session.getCurrentLocale();
String attributeName = mdAttribute.definesAttribute();
LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
boolean required = mdAttribute.isRequired();
boolean unique = mdAttribute.isUnique();
boolean isChangeOverTime = true;
DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
if (defaultAttr != null) {
isChangeOverTime = defaultAttr.isChangeOverTime();
}
if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeDecDAOIF) {
MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
return attributeType;
} else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
} else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
if (rootOid != null && rootOid.length() > 0) {
ClassificationType type = new ClassificationType(mdClassification);
Classification classification = Classification.getByOid(type, rootOid);
attributeType.setRootTerm(classification.toTerm());
}
return attributeType;
} else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
if (mdAttribute instanceof MdAttributeTermDAOIF) {
List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
if (rels.size() > 0) {
RelationshipDAOIF rel = rels.get(0);
BusinessDAO classy = (BusinessDAO) rel.getChild();
TermConverter termBuilder = new TermConverter(classy.getKey());
Term adapterTerm = termBuilder.build();
attributeType.setRootTerm(adapterTerm);
} else {
throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
}
} else {
throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
}
return attributeType;
}
throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
Aggregations