use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class ListTypeVersion method publishNoAuth.
@Transaction
public String publishNoAuth() {
this.lock();
try {
ListType masterlist = this.getListType();
if (!masterlist.isValid()) {
throw new InvalidMasterListException();
}
// Delete tile cache
ListTileCache.deleteTiles(this);
ListCurationHistory.deleteAll(this);
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
mdBusiness.deleteAllRecords();
MdAttributeConcreteDAO status = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("status");
if (status != null) {
ListTypeAttributeGroup.remove(status);
status.delete();
}
MdAttributeConcreteDAO statusDefaultLocale = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("statusDefaultLocale");
if (statusDefaultLocale != null) {
ListTypeAttributeGroup.remove(statusDefaultLocale);
statusDefaultLocale.delete();
}
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
// Add the type ancestor fields
Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
Collection<AttributeType> attributes = type.getAttributeMap().values();
Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
// ServerGeoObjectService service = new ServerGeoObjectService();
// ServerGeoObjectQuery query = service.createQuery(type,
// this.getPeriod());
Date forDate = this.getForDate();
BasicVertexRestriction restriction = masterlist.getRestriction(type, forDate);
BasicVertexQuery query = new BasicVertexQuery(type, forDate);
query.setRestriction(restriction);
Long count = query.getCount();
if (count == null) {
count = 0L;
}
long current = 0;
try {
ProgressService.put(this.getOid(), new Progress(0L, count, ""));
int pageSize = 1000;
long skip = 0;
while (skip < count) {
query = new BasicVertexQuery(type, forDate);
query.setRestriction(restriction);
query.setLimit(pageSize);
query.setSkip(skip);
// List<GeoObjectStatus> validStats = new
// ArrayList<GeoObjectStatus>();
// validStats.add(GeoObjectStatus.ACTIVE);
// validStats.add(GeoObjectStatus.INACTIVE);
// validStats.add(GeoObjectStatus.PENDING);
// validStats.add(GeoObjectStatus.NEW);
// query.setRestriction(new ServerStatusRestriction(validStats,
// this.getForDate(), JoinOp.OR));
List<ServerGeoObjectIF> results = query.getResults();
for (ServerGeoObjectIF result : results) {
Business business = new Business(mdBusiness.definesType());
publish(masterlist, type, result, business, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
Thread.yield();
ProgressService.put(this.getOid(), new Progress(current++, count, ""));
}
skip += pageSize;
}
this.setPublishDate(new Date());
this.apply();
return this.toJSON(true).toString();
} finally {
ProgressService.remove(this.getOid());
}
} finally {
this.unlock();
}
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class MasterListVersion method publishRecord.
@Transaction
public void publishRecord(ServerGeoObjectIF object) {
object.setDate(this.getForDate());
// Delete tile cache
TileCache.deleteTiles(this);
MasterList masterlist = this.getMasterlist();
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
// Add the type ancestor fields
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
Collection<AttributeType> attributes = type.getAttributeMap().values();
Business business = new Business(mdBusiness.definesType());
this.publish(object, business, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class MasterListVersion method createTable.
private TableMetadata createTable() {
MasterList masterlist = this.getMasterlist();
TableMetadata metadata = new TableMetadata();
Locale currentLocale = Session.getCurrentLocale();
String viewName = this.getTableName();
// Create the MdTable
MdBusinessDAO mdTableDAO = MdBusinessDAO.newInstance();
mdTableDAO.setValue(MdTableInfo.NAME, viewName);
mdTableDAO.setValue(MdTableInfo.PACKAGE, RegistryConstants.TABLE_PACKAGE);
mdTableDAO.setStructValue(MdTableInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, masterlist.getDisplayLabel().getValue());
mdTableDAO.setValue(MdTableInfo.TABLE_NAME, viewName);
mdTableDAO.setValue(MdTableInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
mdTableDAO.apply();
MdBusiness mdBusiness = (MdBusiness) BusinessFacade.get(mdTableDAO);
MdAttributeUUIDDAO mdAttributeOriginalId = MdAttributeUUIDDAO.newInstance();
mdAttributeOriginalId.setValue(MdAttributeCharacterInfo.NAME, ORIGINAL_OID);
mdAttributeOriginalId.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeOriginalId.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Original oid");
mdAttributeOriginalId.apply();
metadata.setMdBusiness(mdBusiness);
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
ServerGeoObjectType type = masterlist.getGeoObjectType();
this.createMdAttributeFromAttributeType(mdBusiness, type.getGeometryType());
Collection<AttributeType> attributeTypes = type.getAttributeMap().values();
for (AttributeType attributeType : attributeTypes) {
if (this.isValid(attributeType)) {
createMdAttributeFromAttributeType(metadata, attributeType, type, locales);
}
}
JsonArray hierarchies = masterlist.getHierarchiesAsJson();
for (int i = 0; i < hierarchies.size(); i++) {
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
List<String> pCodes = masterlist.getParentCodes(hierarchy);
if (pCodes.size() > 0) {
String hCode = hierarchy.get("code").getAsString();
ServerHierarchyType hierarchyType = ServiceFactory.getMetadataCache().getHierachyType(hCode).get();
String hierarchyLabel = hierarchyType.getDisplayLabel().getValue(currentLocale);
for (String pCode : pCodes) {
ServerGeoObjectType got = ServerGeoObjectType.get(pCode);
String typeLabel = got.getLabel().getValue(currentLocale);
String attributeName = hCode.toLowerCase() + pCode.toLowerCase();
String label = typeLabel + " (" + hierarchyLabel + ")";
String codeDescription = LocalizationFacade.localize("masterlist.code.description");
codeDescription = codeDescription.replaceAll("\\{typeLabel\\}", typeLabel);
codeDescription = codeDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
String labelDescription = LocalizationFacade.localize("masterlist.label.description");
labelDescription = labelDescription.replaceAll("\\{typeLabel\\}", typeLabel);
labelDescription = labelDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
MdAttributeCharacterDAO mdAttributeCode = MdAttributeCharacterDAO.newInstance();
mdAttributeCode.setValue(MdAttributeCharacterInfo.NAME, attributeName);
mdAttributeCode.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeCode.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label);
mdAttributeCode.addItem(MdAttributeCharacterInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, codeDescription);
mdAttributeCode.apply();
MdAttributeCharacterDAO mdAttributeDefaultLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label + " (defaultLocale)");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", "default"));
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacterDAO mdAttributeLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, label + " (" + locale + ")");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", locale.toString()));
mdAttributeLocale.apply();
}
}
}
}
JsonArray subtypeHierarchies = masterlist.getSubtypeHierarchiesAsJson();
for (int i = 0; i < subtypeHierarchies.size(); i++) {
JsonObject hierarchy = subtypeHierarchies.get(i).getAsJsonObject();
if (hierarchy.has("selected") && hierarchy.get("selected").getAsBoolean()) {
String hCode = hierarchy.get("code").getAsString();
HierarchyType hierarchyType = ServiceFactory.getAdapter().getMetadataCache().getHierachyType(hCode).get();
String hierarchyLabel = hierarchyType.getLabel().getValue(currentLocale);
String attributeName = hCode.toLowerCase();
String codeDescription = LocalizationFacade.localize("masterlist.code.description");
codeDescription = codeDescription.replaceAll("\\{typeLabel\\}", "");
codeDescription = codeDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
String labelDescription = LocalizationFacade.localize("masterlist.label.description");
labelDescription = labelDescription.replaceAll("\\{typeLabel\\}", "");
labelDescription = labelDescription.replaceAll("\\{hierarchyLabel\\}", hierarchyLabel);
MdAttributeCharacterDAO mdAttributeCode = MdAttributeCharacterDAO.newInstance();
mdAttributeCode.setValue(MdAttributeCharacterInfo.NAME, attributeName);
mdAttributeCode.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeCode.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel);
mdAttributeCode.addItem(MdAttributeCharacterInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
mdAttributeCode.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, codeDescription);
mdAttributeCode.apply();
MdAttributeCharacterDAO mdAttributeDefaultLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel + " (defaultLocale)");
mdAttributeDefaultLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", "default"));
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacterDAO mdAttributeLocale = MdAttributeCharacterDAO.newInstance();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeName + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.DEFINING_MD_CLASS, mdTableDAO.getOid());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, hierarchyLabel + " (" + locale + ")");
mdAttributeLocale.setStructValue(MdAttributeCharacterInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, labelDescription.replaceAll("\\{locale\\}", locale.toString()));
mdAttributeLocale.apply();
}
}
}
return metadata;
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class MasterListVersion method publishNoAuth.
@Transaction
public String publishNoAuth() {
this.lock();
try {
MasterList masterlist = this.getMasterlist();
if (!masterlist.isValid()) {
throw new InvalidMasterListException();
}
// Delete tile cache
TileCache.deleteTiles(this);
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
mdBusiness.deleteAllRecords();
MdAttributeConcreteDAO status = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("status");
if (status != null) {
MasterListAttributeGroup.remove(status);
status.delete();
}
MdAttributeConcreteDAO statusDefaultLocale = (MdAttributeConcreteDAO) mdBusiness.definesAttribute("statusDefaultLocale");
if (statusDefaultLocale != null) {
MasterListAttributeGroup.remove(statusDefaultLocale);
statusDefaultLocale.delete();
}
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
// Add the type ancestor fields
Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
Collection<AttributeType> attributes = type.getAttributeMap().values();
Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
// ServerGeoObjectService service = new ServerGeoObjectService();
// ServerGeoObjectQuery query = service.createQuery(type,
// this.getPeriod());
VertexGeoObjectQuery query = new VertexGeoObjectQuery(type, this.getForDate());
Long count = query.getCount();
if (count == null) {
count = 0L;
}
long current = 0;
try {
ProgressService.put(this.getOid(), new Progress(0L, count, ""));
int pageSize = 1000;
long skip = 0;
while (skip < count) {
query = new VertexGeoObjectQuery(type, this.getForDate());
query.setLimit(pageSize);
query.setSkip(skip);
// List<GeoObjectStatus> validStats = new
// ArrayList<GeoObjectStatus>();
// validStats.add(GeoObjectStatus.ACTIVE);
// validStats.add(GeoObjectStatus.INACTIVE);
// validStats.add(GeoObjectStatus.PENDING);
// validStats.add(GeoObjectStatus.NEW);
// query.setRestriction(new ServerStatusRestriction(validStats,
// this.getForDate(), JoinOp.OR));
List<ServerGeoObjectIF> results = query.getResults();
for (ServerGeoObjectIF result : results) {
Business business = new Business(mdBusiness.definesType());
publish(result, business, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
Thread.yield();
ProgressService.put(this.getOid(), new Progress(current++, count, ""));
}
skip += pageSize;
}
this.setPublishDate(new Date());
this.apply();
return this.toJSON(true).toString();
} finally {
ProgressService.remove(this.getOid());
}
} finally {
this.unlock();
}
}
use of org.commongeoregistry.adapter.metadata.AttributeType in project geoprism-registry by terraframe.
the class MasterListVersion method updateRecord.
@Transaction
public void updateRecord(ServerGeoObjectIF object) {
object.setDate(this.getForDate());
// Delete tile cache
TileCache.deleteTiles(this);
MasterList masterlist = this.getMasterlist();
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
// Add the type ancestor fields
ServerGeoObjectType type = ServerGeoObjectType.get(masterlist.getUniversal());
Set<ServerHierarchyType> hierarchiesOfSubTypes = type.getHierarchiesOfSubTypes();
Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap = masterlist.getAncestorMap(type);
Collection<AttributeType> attributes = type.getAttributeMap().values();
BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
query.WHERE(query.aCharacter(DefaultAttribute.CODE.getName()).EQ(object.getCode()));
List<Business> records = query.getIterator().getAll();
for (Business record : records) {
try {
record.appLock();
this.publish(object, record, attributes, ancestorMap, hierarchiesOfSubTypes, locales);
} finally {
record.unlock();
}
}
}
Aggregations