Search in sources :

Example 1 with EntityDefinitionType

use of org.motechproject.mds.domain.EntityDefinitionType 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 EntityDefinitionType

use of org.motechproject.mds.domain.EntityDefinitionType in project motech by motech.

the class ImportReader method beginEntry.

public EntryReader beginEntry() throws IOException {
    jsonReader.beginObject();
    String entityName = objectReader.readString("entity");
    EntityDefinitionType entityType = objectReader.readEnum("type", EntityDefinitionType.class);
    Entity entity = importContext.getEntity(entityName);
    return new EntryReader(jsonReader, entityName, entityType, entity, importContext);
}
Also used : EntityDefinitionType(org.motechproject.mds.domain.EntityDefinitionType) Entity(org.motechproject.mds.domain.Entity)

Aggregations

Entity (org.motechproject.mds.domain.Entity)2 EntityDefinitionType (org.motechproject.mds.domain.EntityDefinitionType)2 JsonParseException (com.google.gson.JsonParseException)1 ImportManifest (org.motechproject.mds.domain.ImportManifest)1