use of org.motechproject.mds.domain.ImportManifest in project motech by motech.
the class ImportManifestReader method readManifest.
public ImportManifest readManifest() throws IOException {
ImportManifest manifest = new ImportManifest();
jsonReader.beginArray();
while (jsonReader.hasNext()) {
jsonReader.beginObject();
String entityName = objectReader.readString("entity");
EntityDefinitionType entityType = objectReader.readEnum("type", EntityDefinitionType.class);
Entity existingEntity = getExistingEntity(entityName);
boolean canImport = isImportable(existingEntity, entityType);
String moduleName = null != existingEntity && existingEntity.isDDE() ? existingEntity.getModule() : "MDS";
ImportManifest.Record manifestRecord = manifest.addRecord(entityName, moduleName);
objectReader.expectAndSkip("schema");
manifestRecord.setCanIncludeSchema(canImport);
if (jsonReader.hasNext()) {
objectReader.expectAndSkip("instances");
manifestRecord.setCanIncludeData(canImport);
}
if (jsonReader.hasNext()) {
throw new JsonParseException("Invalid json format! Unexpected property: " + jsonReader.nextName());
}
jsonReader.endObject();
}
jsonReader.endArray();
return manifest;
}
use of org.motechproject.mds.domain.ImportManifest in project motech by motech.
the class ImportExportServiceImpl method saveImportFileAndExtractManifest.
@Override
@Transactional
public ImportManifest saveImportFileAndExtractManifest(byte[] bytes) {
try {
ImportManifest manifest = extractManifest(bytes);
File file = createImportFile();
FileUtils.writeByteArrayToFile(file, bytes);
manifest.setImportId(getImportId(file));
return manifest;
} catch (IOException e) {
throw new ImportExportException("Cannot save import file", e);
}
}
Aggregations