use of org.commongeoregistry.adapter.dataaccess.LocalizedValue 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 org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class DirectedAcyclicGraphType method create.
public static DirectedAcyclicGraphType create(JsonObject object) {
String code = object.get(DirectedAcyclicGraphType.CODE).getAsString();
LocalizedValue label = LocalizedValue.fromJSON(object.getAsJsonObject(DirectedAcyclicGraphType.JSON_LABEL));
LocalizedValue description = LocalizedValue.fromJSON(object.getAsJsonObject(DirectedAcyclicGraphType.DESCRIPTION));
return create(code, label, description);
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class ListTypeVersion method publish.
private void publish(ListType listType, ServerGeoObjectType type, ServerGeoObjectIF go, Business business, Collection<AttributeType> attributes, Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap, Set<ServerHierarchyType> hierarchiesOfSubTypes, Collection<Locale> locales) {
VertexServerGeoObject vertexGo = (VertexServerGeoObject) go;
business.setValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME, go.getGeometry());
for (AttributeType attribute : attributes) {
String name = attribute.getName();
business.setValue(ORIGINAL_OID, go.getRunwayId());
if (this.isValid(attribute)) {
Object value = go.getValue(name, this.getForDate());
if (value != null) {
if (value instanceof LocalizedValue && ((LocalizedValue) value).isNull()) {
continue;
}
if (attribute instanceof AttributeTermType) {
Classifier classifier = (Classifier) value;
Term term = ((AttributeTermType) attribute).getTermByCode(classifier.getClassifierId()).get();
LocalizedValue label = term.getLabel();
this.setValue(business, name, term.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Classification classification = Classification.getByOid(classificationType, (String) value);
LocalizedValue label = classification.getDisplayLabel();
this.setValue(business, name, classification.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeLocalType) {
LocalizedValue label = (LocalizedValue) value;
String defaultLocale = label.getValue(LocalizedValue.DEFAULT_LOCALE);
if (defaultLocale == null) {
defaultLocale = "";
}
this.setValue(business, name + DEFAULT_LOCALE, defaultLocale);
for (Locale locale : locales) {
String localeValue = label.getValue(locale);
if (localeValue == null) {
localeValue = "";
}
this.setValue(business, name + locale.toString(), localeValue);
}
} else {
this.setValue(business, name, value);
}
}
}
}
Set<Entry<ServerHierarchyType, List<ServerGeoObjectType>>> entries = ancestorMap.entrySet();
for (Entry<ServerHierarchyType, List<ServerGeoObjectType>> entry : entries) {
ServerHierarchyType hierarchy = entry.getKey();
Map<String, LocationInfo> map = vertexGo.getAncestorMap(hierarchy, entry.getValue());
Set<Entry<String, LocationInfo>> locations = map.entrySet();
for (Entry<String, LocationInfo> location : locations) {
String pCode = location.getKey();
LocationInfo vObject = location.getValue();
if (vObject != null) {
String attributeName = hierarchy.getCode().toLowerCase() + pCode.toLowerCase();
this.setValue(business, attributeName, vObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, vObject.getLabel());
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), vObject.getLabel(locale));
}
}
}
}
for (ServerHierarchyType hierarchy : hierarchiesOfSubTypes) {
ServerParentTreeNode node = go.getParentsForHierarchy(hierarchy, false, this.getForDate());
List<ServerParentTreeNode> parents = node.getParents();
if (parents.size() > 0) {
ServerParentTreeNode parent = parents.get(0);
String attributeName = hierarchy.getCode().toLowerCase();
ServerGeoObjectIF geoObject = parent.getGeoObject();
LocalizedValue label = geoObject.getDisplayLabel();
this.setValue(business, attributeName, geoObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, label.getValue(DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), label.getValue(locale));
}
}
}
if (type.getGeometryType().equals(GeometryType.MULTIPOINT) || type.getGeometryType().equals(GeometryType.POINT) && listType.getIncludeLatLong()) {
Geometry geom = vertexGo.getGeometry();
if (geom instanceof MultiPoint) {
MultiPoint mp = (MultiPoint) geom;
Coordinate[] coords = mp.getCoordinates();
Coordinate firstCoord = coords[0];
this.setValue(business, "latitude", String.valueOf(firstCoord.y));
this.setValue(business, "longitude", String.valueOf(firstCoord.x));
} else if (geom instanceof Point) {
Point point = (Point) geom;
Coordinate firstCoord = point.getCoordinate();
this.setValue(business, "latitude", String.valueOf(firstCoord.y));
this.setValue(business, "longitude", String.valueOf(firstCoord.x));
}
}
business.apply();
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class MasterListVersion method publish.
private void publish(ServerGeoObjectIF go, Business business, Collection<AttributeType> attributes, Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap, Set<ServerHierarchyType> hierarchiesOfSubTypes, Collection<Locale> locales) {
VertexServerGeoObject vertexGo = (VertexServerGeoObject) go;
boolean hasData = false;
business.setValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME, go.getGeometry());
for (AttributeType attribute : attributes) {
String name = attribute.getName();
business.setValue(ORIGINAL_OID, go.getRunwayId());
if (this.isValid(attribute)) {
Object value = go.getValue(name, this.getForDate());
if (value != null) {
if (value instanceof LocalizedValue && ((LocalizedValue) value).isNull()) {
continue;
}
if (!name.equals(DefaultAttribute.CODE.getName()) && !name.equals(DefaultAttribute.INVALID.getName()) && attribute.isChangeOverTime() && (!name.equals(DefaultAttribute.EXISTS.getName()) || (value instanceof Boolean && ((Boolean) value)))) {
hasData = true;
}
if (attribute instanceof AttributeTermType) {
Classifier classifier = (Classifier) value;
Term term = ((AttributeTermType) attribute).getTermByCode(classifier.getClassifierId()).get();
LocalizedValue label = term.getLabel();
this.setValue(business, name, term.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
LocalizedValue label = LocalizedValueConverter.convert(classification.getEmbeddedComponent(AbstractClassification.DISPLAYLABEL));
this.setValue(business, name, classification.getObjectValue(AbstractClassification.CODE));
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeLocalType) {
LocalizedValue label = (LocalizedValue) value;
String defaultLocale = label.getValue(LocalizedValue.DEFAULT_LOCALE);
if (defaultLocale == null) {
defaultLocale = "";
}
this.setValue(business, name + DEFAULT_LOCALE, defaultLocale);
for (Locale locale : locales) {
String localeValue = label.getValue(locale);
if (localeValue == null) {
localeValue = "";
}
this.setValue(business, name + locale.toString(), localeValue);
}
} else {
this.setValue(business, name, value);
}
}
}
}
if (hasData) {
Set<Entry<ServerHierarchyType, List<ServerGeoObjectType>>> entries = ancestorMap.entrySet();
for (Entry<ServerHierarchyType, List<ServerGeoObjectType>> entry : entries) {
ServerHierarchyType hierarchy = entry.getKey();
Map<String, LocationInfo> map = vertexGo.getAncestorMap(hierarchy, entry.getValue());
Set<Entry<String, LocationInfo>> locations = map.entrySet();
for (Entry<String, LocationInfo> location : locations) {
String pCode = location.getKey();
LocationInfo vObject = location.getValue();
if (vObject != null) {
String attributeName = hierarchy.getCode().toLowerCase() + pCode.toLowerCase();
this.setValue(business, attributeName, vObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, vObject.getLabel());
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), vObject.getLabel(locale));
}
}
}
}
for (ServerHierarchyType hierarchy : hierarchiesOfSubTypes) {
ServerParentTreeNode node = go.getParentsForHierarchy(hierarchy, false, this.getForDate());
List<ServerParentTreeNode> parents = node.getParents();
if (parents.size() > 0) {
ServerParentTreeNode parent = parents.get(0);
String attributeName = hierarchy.getCode().toLowerCase();
ServerGeoObjectIF geoObject = parent.getGeoObject();
LocalizedValue label = geoObject.getDisplayLabel();
this.setValue(business, attributeName, geoObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, label.getValue(DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), label.getValue(locale));
}
}
}
business.apply();
}
}
use of org.commongeoregistry.adapter.dataaccess.LocalizedValue in project geoprism-registry by terraframe.
the class SynchronizationConfig method toJSON.
@Override
public JsonObject toJSON() {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(FhirSyncLevel.class, new FhirSyncLevel.Serializer());
builder.registerTypeAdapter(DHIS2AttributeMapping.class, new DHIS2AttributeMapping.DHIS2AttributeMappingDeserializer());
Gson gson = builder.create();
JsonObject object = new JsonObject();
object.addProperty(SynchronizationConfig.OID, this.getOid());
object.addProperty(SynchronizationConfig.ORGANIZATION, this.getOrganization().getCode());
object.addProperty(SynchronizationConfig.SYSTEM, this.getSystem());
object.add(SynchronizationConfig.LABEL, LocalizedValueConverter.convert(this.getLabel()).toJSON());
object.addProperty(SynchronizationConfig.ISIMPORT, this.getIsImport() != null ? this.getIsImport() : false);
ExternalSystemSyncConfig config = this.buildConfiguration();
object.add(SynchronizationConfig.CONFIGURATION, gson.toJsonTree(config));
ExternalSystem system = this.getExternalSystem();
if (system != null) {
LocalizedValue label = LocalizedValueConverter.convert(system.getEmbeddedComponent(ExternalSystem.LABEL));
object.addProperty(SynchronizationConfig.TYPE, system.getClass().getSimpleName());
object.addProperty(SynchronizationConfig.SYSTEM_LABEL, label.getValue());
}
return object;
}
Aggregations