Search in sources :

Example 1 with ImportManifest

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;
}
Also used : ImportManifest(org.motechproject.mds.domain.ImportManifest) EntityDefinitionType(org.motechproject.mds.domain.EntityDefinitionType) Entity(org.motechproject.mds.domain.Entity) JsonParseException(com.google.gson.JsonParseException)

Example 2 with ImportManifest

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);
    }
}
Also used : ImportManifest(org.motechproject.mds.domain.ImportManifest) ImportExportException(org.motechproject.mds.exception.importexport.ImportExportException) IOException(java.io.IOException) File(java.io.File) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ImportManifest (org.motechproject.mds.domain.ImportManifest)2 JsonParseException (com.google.gson.JsonParseException)1 File (java.io.File)1 IOException (java.io.IOException)1 Entity (org.motechproject.mds.domain.Entity)1 EntityDefinitionType (org.motechproject.mds.domain.EntityDefinitionType)1 ImportExportException (org.motechproject.mds.exception.importexport.ImportExportException)1 Transactional (org.springframework.transaction.annotation.Transactional)1