use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class GeoObjectUtilTest method testGetAncestorMapForTreeType.
@Test
@Request
public void testGetAncestorMapForTreeType() {
ServerGeoObjectType type = USATestData.AREA.getServerObject();
ServerHierarchyType hierarchyType = ServerHierarchyType.get(USATestData.HIER_ADMIN.getCode());
ServerGeoObjectIF object = new ServerGeoObjectService().getGeoObjectByCode(USATestData.CO_A_ONE.getCode(), type);
List<GeoObjectType> dtoAncestors = type.getTypeAncestors(hierarchyType, true);
List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
for (GeoObjectType ancestor : dtoAncestors) {
ancestors.add(ServerGeoObjectType.get(ancestor));
}
Map<String, LocationInfo> map = object.getAncestorMap(hierarchyType, ancestors);
Assert.assertEquals(3, map.size());
// Validate the county values
Assert.assertTrue(map.containsKey(USATestData.COUNTY.getCode()));
LocationInfo vObject = map.get(USATestData.COUNTY.getCode());
Assert.assertEquals(USATestData.CO_C_ONE.getCode(), vObject.getCode());
Assert.assertEquals(USATestData.CO_C_ONE.getDisplayLabel(), vObject.getLabel());
// Validate the state values
Assert.assertTrue(map.containsKey(USATestData.STATE.getCode()));
vObject = map.get(USATestData.STATE.getCode());
Assert.assertEquals(USATestData.COLORADO.getCode(), vObject.getCode());
Assert.assertEquals(USATestData.COLORADO.getDisplayLabel(), vObject.getLabel());
// Validate the country values
Assert.assertTrue(map.containsKey(USATestData.COUNTRY.getCode()));
vObject = map.get(USATestData.COUNTRY.getCode());
Assert.assertEquals(USATestData.USA.getCode(), vObject.getCode());
Assert.assertEquals(USATestData.USA.getDisplayLabel(), vObject.getLabel());
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class ListType method markAsInvalid.
public void markAsInvalid(ServerGeoObjectType type) {
boolean isValid = true;
JsonArray hierarchies = this.getHierarchiesAsJson();
ServerGeoObjectType masterlistType = this.getGeoObjectType();
for (int i = 0; i < hierarchies.size(); i++) {
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
String hCode = hierarchy.get("code").getAsString();
Optional<ServerHierarchyType> ht = ServiceFactory.getMetadataCache().getHierachyType(hCode);
if (ht.isPresent()) {
List<String> pCodes = this.getParentCodes(hierarchy);
if (pCodes.contains(type.getCode()) || type.getCode().equals(masterlistType.getCode())) {
isValid = false;
}
} else {
isValid = false;
}
}
if (!isValid) {
this.appLock();
this.setValid(false);
this.apply();
}
}
use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class ListType method getAncestorMap.
public Map<ServerHierarchyType, List<ServerGeoObjectType>> getAncestorMap(ServerGeoObjectType type) {
Map<ServerHierarchyType, List<ServerGeoObjectType>> map = new HashMap<>();
JsonArray hierarchies = this.getHierarchiesAsJson();
for (int i = 0; i < hierarchies.size(); i++) {
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
List<String> pCodes = this.getParentCodes(hierarchy);
if (pCodes.size() > 0) {
String hCode = hierarchy.get("code").getAsString();
ServerHierarchyType hierarchyType = ServerHierarchyType.get(hCode);
List<GeoObjectType> dtoAncestors = type.getTypeAncestors(hierarchyType, true);
List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
for (GeoObjectType ancestor : dtoAncestors) {
ancestors.add(ServerGeoObjectType.get(ancestor));
}
map.put(hierarchyType, ancestors);
}
}
return map;
}
use of net.geoprism.registry.model.ServerHierarchyType 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 net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.
the class MasterList method markAsInvalid.
public void markAsInvalid(ServerGeoObjectType type) {
boolean isValid = true;
JsonArray hierarchies = this.getHierarchiesAsJson();
ServerGeoObjectType masterlistType = this.getGeoObjectType();
for (int i = 0; i < hierarchies.size(); i++) {
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
String hCode = hierarchy.get("code").getAsString();
Optional<ServerHierarchyType> ht = ServiceFactory.getMetadataCache().getHierachyType(hCode);
if (ht.isPresent()) {
List<String> pCodes = this.getParentCodes(hierarchy);
if (pCodes.contains(type.getCode()) || type.getCode().equals(masterlistType.getCode())) {
isValid = false;
}
} else {
isValid = false;
}
}
if (!isValid) {
this.appLock();
this.setValid(false);
this.apply();
}
}
Aggregations