use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class MasterListShapefileExporter method writeDictionaryFile.
/**
* Writes an additional "data dictionary" / metadata excel spreadsheet to the directory, which is intended to be
* part of the final Shapfile. This is useful for downstream developers trying to make sense of the GIS data.
*
* See also:
* - https://github.com/terraframe/geoprism-registry/issues/628
*/
private void writeDictionaryFile(File directory) {
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.version.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.version.isValid(mdAttribute)).collect(Collectors.toList());
mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
String excelFilter;
if (filterJson == null) {
excelFilter = "[{attribute:invalid,value:false}]";
} else {
excelFilter = new String(filterJson);
}
try {
File file = new File(directory, "metadata.xlsx");
FileOutputStream fos = new FileOutputStream(file);
MasterListExcelExporter exporter = new MasterListExcelExporter(this.version, mdBusiness, mdAttributes, excelFilter, this.columnNames, new MasterListExcelExporterSheet[] { MasterListExcelExporterSheet.DICTIONARY, MasterListExcelExporterSheet.METADATA });
Workbook wb = exporter.createWorkbook();
wb.write(fos);
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class ListTypeTest method testPublishVersion.
//
// @Test
// public void testPrivateListByOrgFromOtherOrg()
// {
// JsonObject listJson = getJson(USATestData.ORG_NPS.getServerObject(),
// USATestData.HIER_ADMIN, USATestData.STATE, ListType.PRIVATE, false);
//
// ListTypeService service = new ListTypeService();
// JsonObject result = service.apply(testData.clientRequest.getSessionId(),
// listJson);
//
// try
// {
// USATestData.runAsUser(USATestData.USER_PPP_RA, (request, adapter) -> {
// JsonArray orgs = service.listByOrg(request.getSessionId());
//
// JsonObject org = null;
// for (int i = 0; i < orgs.size(); ++i)
// {
// if
// (orgs.get(i).getAsJsonObject().get("oid").getAsString().equals(USATestData.ORG_NPS.getServerObject().getOid()))
// {
// org = orgs.get(i).getAsJsonObject();
// }
// }
//
// Assert.assertNotNull(org.get("oid").getAsString());
// Assert.assertEquals(USATestData.ORG_NPS.getDisplayLabel(),
// org.get("label").getAsString());
// Assert.assertFalse(org.get("write").getAsBoolean());
// Assert.assertTrue(org.get("lists").getAsJsonArray().size() == 0);
// });
// }
// finally
// {
// String oid = result.get(ComponentInfo.OID).getAsString();
// service.remove(testData.clientRequest.getSessionId(), oid);
// }
// }
//
@Test
@Request
public void testPublishVersion() {
USATestData.runAsUser(USATestData.USER_ADMIN, (request, adapter) -> {
JsonObject json = getJson(USATestData.ORG_NPS.getServerObject(), USATestData.HIER_ADMIN, USATestData.STATE, USATestData.COUNTRY);
ListType test = ListType.apply(json);
try {
ListTypeEntry entry = test.createEntry(TestDataSet.DEFAULT_OVER_TIME_DATE);
try {
entry.publish(createVersionMetadata().toString());
List<ListTypeVersion> versions = entry.getVersions();
Assert.assertEquals(2, versions.size());
ListTypeVersion version = versions.get(0);
MdBusinessDAOIF mdTable = MdBusinessDAO.get(version.getMdBusinessOid());
Assert.assertNotNull(mdTable);
} finally {
entry.delete();
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
} finally {
test.delete();
}
});
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class GeoRegistryUtil method exportMasterListExcel.
@Transaction
public static InputStream exportMasterListExcel(String oid, String filterJson) {
MasterListVersion version = MasterListVersion.get(oid);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(version.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> version.isValid(mdAttribute)).collect(Collectors.toList());
if (filterJson.contains("invalid")) {
mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
}
try {
MasterListExcelExporter exporter = new MasterListExcelExporter(version, mdBusiness, mdAttributes, filterJson, null);
return exporter.export();
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class GeoRegistryUtil method exportListTypeShapefile.
@Transaction
public static InputStream exportListTypeShapefile(String oid, String json) {
ListTypeVersion version = ListTypeVersion.get(oid);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(version.getMdBusinessOid());
JsonObject criteria = (json != null) ? JsonParser.parseString(json).getAsJsonObject() : new JsonObject();
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> version.isValid(mdAttribute)).collect(Collectors.toList());
if (json.contains("invalid")) {
mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
}
try {
ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(version, mdBusiness, mdAttributes, criteria);
return exporter.export();
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.MdBusinessDAOIF in project geoprism-registry by terraframe.
the class ListTypeVersion method generateShapefile.
// public List<ExecutableJob> getJobs()
// {
// LinkedList<ExecutableJob> jobs = new LinkedList<ExecutableJob>();
//
// PublishShapefileJobQuery psjq = new PublishShapefileJobQuery(new
// QueryFactory());
// psjq.WHERE(psjq.getVersion().EQ(this));
//
// try (OIterator<? extends PublishShapefileJob> it = psjq.getIterator())
// {
// jobs.addAll(it.getAll());
// }
//
// PublishListTypeVersionJobQuery pmlvj = new
// PublishListTypeVersionJobQuery(new QueryFactory());
// pmlvj.WHERE(pmlvj.getListTypeVersion().EQ(this));
//
// try (OIterator<? extends PublishListTypeVersionJob> it =
// pmlvj.getIterator())
// {
// jobs.addAll(it.getAll());
// }
//
// return jobs;
// }
public File generateShapefile() {
String filename = this.getOid() + ".zip";
final ListType list = this.getListType();
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 {
ListTypeShapefileExporter exporter = new ListTypeShapefileExporter(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;
}
Aggregations