use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class MasterListVersion method generateShapefile.
public File generateShapefile() {
String filename = this.getOid() + ".zip";
final MasterList list = this.getMasterlist();
final File directory = list.getShapefileDirectory();
directory.mkdirs();
final File file = new File(directory, filename);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.isValid(mdAttribute)).collect(Collectors.toList());
try {
MasterListShapefileExporter exporter = new MasterListShapefileExporter(this, mdBusiness, mdAttributes, null);
try (final InputStream istream = exporter.export()) {
try (final FileOutputStream fos = new FileOutputStream(file)) {
IOUtils.copy(istream, fos);
}
}
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
return file;
}
use of com.runwaysdk.system.metadata.MdBusiness 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 com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class MasterListVersion method createMdAttributeFromAttributeType.
protected static void createMdAttributeFromAttributeType(TableMetadata metadata, AttributeType attributeType, ServerGeoObjectType type, Collection<Locale> locales) {
MdBusiness mdBusiness = metadata.getMdBusiness();
if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
MdAttributeConcrete mdAttribute = null;
if (attributeType.getType().equals(AttributeCharacterType.TYPE)) {
mdAttribute = new MdAttributeCharacter();
MdAttributeCharacter mdAttributeCharacter = (MdAttributeCharacter) mdAttribute;
mdAttributeCharacter.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
} else if (attributeType.getType().equals(AttributeDateType.TYPE)) {
mdAttribute = new MdAttributeDateTime();
} else if (attributeType.getType().equals(AttributeIntegerType.TYPE)) {
mdAttribute = new MdAttributeLong();
} else if (attributeType.getType().equals(AttributeFloatType.TYPE)) {
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute = new MdAttributeDouble();
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType.getType().equals(AttributeBooleanType.TYPE)) {
mdAttribute = new MdAttributeBoolean();
} else {
throw new UnsupportedOperationException("Unsupported type [" + attributeType.getType() + "]");
}
mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
mdAttribute.setDefiningMdClass(mdBusiness);
mdAttribute.apply();
} else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
MdAttributeCharacter cloneAttribute = new MdAttributeCharacter();
cloneAttribute.setValue(MdAttributeConcreteInfo.NAME, attributeType.getName());
cloneAttribute.setValue(MdAttributeCharacterInfo.SIZE, "255");
cloneAttribute.addIndexType(MdAttributeIndices.NON_UNIQUE_INDEX);
LocalizedValueConverter.populate(cloneAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(cloneAttribute.getDescription(), attributeType.getDescription());
cloneAttribute.setDefiningMdClass(mdBusiness);
cloneAttribute.apply();
metadata.addPair(cloneAttribute, cloneAttribute);
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
metadata.addPair(mdAttributeDefaultLocale, cloneAttribute);
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
metadata.addPair(mdAttributeLocale, cloneAttribute);
}
// MdAttributeUUID mdAttributeOid = new MdAttributeUUID();
// mdAttributeOid.setValue(MdAttributeConcreteInfo.NAME,
// attributeType.getName() + "Oid");
// AbstractBuilder.populate(mdAttributeOid.getDisplayLabel(),
// attributeType.getLabel());
// AbstractBuilder.populate(mdAttributeOid.getDescription(),
// attributeType.getDescription());
// mdAttributeOid.setDefiningMdClass(mdBusiness);
// mdAttributeOid.apply();
} else if (attributeType instanceof AttributeLocalType) {
boolean isDisplayLabel = attributeType.getName().equals(DefaultAttribute.DISPLAY_LABEL.getName());
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
}
}
}
use of com.runwaysdk.system.metadata.MdBusiness in project geoprism-registry by terraframe.
the class MasterListVersion method delete.
@Override
@Transaction
public void delete() {
// Delete all jobs
List<ExecutableJob> jobs = this.getJobs();
for (ExecutableJob job : jobs) {
job.delete();
}
// Delete tile cache
TileCache.deleteTiles(this);
MasterListAttributeGroup.deleteAll(this);
MdBusiness mdTable = this.getMdBusiness();
super.delete();
if (mdTable != null) {
MdBusinessDAO mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid()).getBusinessDAO();
mdBusiness.deleteAllRecords();
mdTable.delete();
}
if (this.getVersionType().equals(MasterListVersion.PUBLISHED)) {
// new GeoserverRemoveWMSCommand(this).doIt();
}
}
use of com.runwaysdk.system.metadata.MdBusiness 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