use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO in project geoprism-registry by terraframe.
the class BusinessType method apply.
@Transaction
public static BusinessType apply(JsonObject object) {
String code = object.get(BusinessType.CODE).getAsString();
String organizationCode = object.get(BusinessType.ORGANIZATION).getAsString();
Organization organization = Organization.getByCode(organizationCode);
ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(organization.getCode(), false);
if (!MasterList.isValidName(code)) {
throw new InvalidMasterListCodeException("The geo object type code has an invalid character");
}
if (code.length() > 64) {
// Setting the typename on the MdBusiness creates this limitation.
CodeLengthException ex = new CodeLengthException();
ex.setLength(64);
throw ex;
}
// assignSRAPermissions(mdVertex, mdBusiness);
// assignAll_RA_Permissions(mdVertex, mdBusiness, organizationCode);
LocalizedValue localizedValue = LocalizedValue.fromJSON(object.get(DISPLAYLABEL).getAsJsonObject());
BusinessType businessType = (object.has(OID) && !object.get(OID).isJsonNull()) ? BusinessType.get(object.get(OID).getAsString()) : new BusinessType();
businessType.setCode(code);
businessType.setOrganization(organization);
LocalizedValueConverter.populate(businessType.getDisplayLabel(), localizedValue);
boolean isNew = businessType.isNew();
if (isNew) {
MdVertexDAO mdVertex = MdVertexDAO.newInstance();
mdVertex.setValue(MdGeoVertexInfo.PACKAGE, RegistryConstants.BUSINESS_PACKAGE);
mdVertex.setValue(MdGeoVertexInfo.NAME, code);
mdVertex.setValue(MdGeoVertexInfo.ENABLE_CHANGE_OVER_TIME, MdAttributeBooleanInfo.FALSE);
mdVertex.setValue(MdGeoVertexInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
LocalizedValueConverter.populate(mdVertex, MdVertexInfo.DISPLAY_LABEL, localizedValue);
mdVertex.apply();
// TODO CREATE the edge between this class and GeoVertex??
MdVertexDAOIF mdGeoVertexDAO = MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS);
MdAttributeGraphReferenceDAO mdGeoObject = MdAttributeGraphReferenceDAO.newInstance();
mdGeoObject.setValue(MdAttributeGraphReferenceInfo.REFERENCE_MD_VERTEX, mdGeoVertexDAO.getOid());
mdGeoObject.setValue(MdAttributeGraphReferenceInfo.DEFINING_MD_CLASS, mdVertex.getOid());
mdGeoObject.setValue(MdAttributeGraphReferenceInfo.NAME, GEO_OBJECT);
mdGeoObject.setStructValue(MdAttributeGraphReferenceInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Geo Object");
mdGeoObject.apply();
// DefaultAttribute.CODE
MdAttributeCharacterDAO vertexCodeMdAttr = MdAttributeCharacterDAO.newInstance();
vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.CODE.getName());
vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultLocalizedName());
vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultDescription());
vertexCodeMdAttr.setValue(MdAttributeCharacterInfo.SIZE, MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdVertex.getOid());
vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
vertexCodeMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.UNIQUE_INDEX.getOid());
vertexCodeMdAttr.apply();
businessType.setMdVertexId(mdVertex.getOid());
// Assign permissions
Roles role = Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE);
RoleDAO roleDAO = (RoleDAO) BusinessFacade.getEntityDAO(role);
roleDAO.grantPermission(Operation.CREATE, mdVertex.getOid());
roleDAO.grantPermission(Operation.DELETE, mdVertex.getOid());
roleDAO.grantPermission(Operation.WRITE, mdVertex.getOid());
roleDAO.grantPermission(Operation.WRITE_ALL, mdVertex.getOid());
}
businessType.apply();
return businessType;
}
use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO 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.metadata.graph.MdVertexDAO in project geoprism-registry by terraframe.
the class ServerGeoObjectType method createMdAttributeFromAttributeType.
/**
* Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
* from the given {@link AttributeType}
*
* @pre assumes no attribute has been defined on the type with the given name.
* @param geoObjectType
* TODO
* @param mdBusiness
* Type to receive attribute definition
* @param attributeType
* newly defined attribute
*
* @return {@link AttributeType}
*/
@Transaction
public MdAttributeConcrete createMdAttributeFromAttributeType(AttributeType attributeType) {
MdAttributeConcrete mdAttribute = ServerGeoObjectType.createMdAttributeFromAttributeType(this.mdBusiness, attributeType);
ListType.createMdAttribute(this, attributeType);
((MdVertexDAO) this.mdVertex).copyAttribute(MdAttributeDAO.get(mdAttribute.getOid()));
return mdAttribute;
}
use of com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO in project geoprism-registry by terraframe.
the class SearchService method createSearchTable.
@Transaction
public void createSearchTable() {
String suffix = this.getSuffix();
String typeName = VERTEX_PREFIX + suffix;
MdVertexDAO mdVertex = MdVertexDAO.newInstance();
mdVertex.setValue(MdVertexInfo.PACKAGE, PACKAGE);
mdVertex.setValue(MdVertexInfo.NAME, typeName);
mdVertex.setValue(MdVertexInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
mdVertex.apply();
MdAttributeTextDAO label = MdAttributeTextDAO.newInstance();
label.setValue(MdAttributeTextInfo.NAME, LABEL);
label.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
label.apply();
MdAttributeTextDAO code = MdAttributeTextDAO.newInstance();
code.setValue(MdAttributeTextInfo.NAME, CODE);
code.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
code.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
code.apply();
MdAttributeTextDAO vertexType = MdAttributeTextDAO.newInstance();
vertexType.setValue(MdAttributeTextInfo.NAME, VERTEX_TYPE);
vertexType.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
vertexType.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
vertexType.apply();
MdAttributeDateDAO startDate = MdAttributeDateDAO.newInstance();
startDate.setValue(MdAttributeTextInfo.NAME, START_DATE);
startDate.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
startDate.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
startDate.apply();
MdAttributeDateDAO endDate = MdAttributeDateDAO.newInstance();
endDate.setValue(MdAttributeTextInfo.NAME, END_DATE);
endDate.setValue(MdAttributeTextInfo.DEFINING_MD_CLASS, mdVertex.getOid());
endDate.setValue(MdAttributeTextInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
endDate.apply();
MdEdgeDAO mdEdge = MdEdgeDAO.newInstance();
mdEdge.setValue(MdVertexInfo.PACKAGE, PACKAGE);
mdEdge.setValue(MdVertexInfo.NAME, EDGE_PREFIX + suffix);
mdEdge.setValue(MdEdgeInfo.PARENT_MD_VERTEX, mdVertex.getOid());
mdEdge.setValue(MdEdgeInfo.CHILD_MD_VERTEX, MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS).getOid());
mdEdge.apply();
GraphDBService service = GraphDBService.getInstance();
GraphRequest dml = service.getGraphDBRequest();
GraphRequest ddl = service.getDDLGraphDBRequest();
String attributeName = label.getValue(MdAttributeTextInfo.NAME);
String className = mdVertex.getDBClassName();
String indexName = className + "." + attributeName;
String statement = "CREATE INDEX " + indexName + " ON " + className + "(" + attributeName + ") FULLTEXT ENGINE LUCENE";
GraphDDLCommandAction action = service.ddlCommand(dml, ddl, statement, new HashMap<String, Object>());
action.execute();
this.assignAllPermissions(Roles.findRoleByName(RegistryConstants.REGISTRY_SUPER_ADMIN_ROLE), mdVertex, mdEdge);
this.assignAllPermissions(Roles.findRoleByName(RegistryConstants.REGISTRY_ADMIN_ROLE), mdVertex, mdEdge);
this.assignAllPermissions(Roles.findRoleByName(RegistryConstants.REGISTRY_MAINTAINER_ROLE), mdVertex, mdEdge);
}
Aggregations