Search in sources :

Example 1 with EntityProcessorOutput

use of org.motechproject.mds.annotations.internal.EntityProcessorOutput in project motech by motech.

the class EditableLookupsLoaderTest method prepareOutput.

private void prepareOutput() {
    EntityProcessorOutput entityProcessorOutput = new EntityProcessorOutput();
    entityProcessorOutput.setEntityProcessingResult(prepareEntityDto());
    List<EntityProcessorOutput> entityProcessorOutputs = new ArrayList<>();
    entityProcessorOutputs.add(entityProcessorOutput);
    output = new MDSProcessorOutput(entityProcessorOutputs, new HashMap<>(), bundle);
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) EntityProcessorOutput(org.motechproject.mds.annotations.internal.EntityProcessorOutput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 2 with EntityProcessorOutput

use of org.motechproject.mds.annotations.internal.EntityProcessorOutput in project motech by motech.

the class MdsBundleWatcher method processAnnotationScanningResults.

private void processAnnotationScanningResults(MDSProcessorOutput output) {
    Map<String, Long> entityIdMappings = new HashMap<>();
    Set<String> newEntities = new HashSet<>();
    Bundle bundle = output.getBundle();
    try {
        migrationService.processBundle(bundle);
    } catch (IOException e) {
        LOGGER.error("An error occurred while copying the migrations from bundle: {}", bundle.getSymbolicName(), e);
    }
    try {
        editableLookupsLoader.addEditableLookups(output, bundle);
    } catch (MdsException e) {
        LOGGER.error("Unable to read JSON defined lookups from bundle: {}", bundle, e);
    }
    for (EntityProcessorOutput result : output.getEntityProcessorOutputs()) {
        EntityDto processedEntity = result.getEntityProcessingResult();
        EntityDto entity = entityService.getEntityByClassName(processedEntity.getClassName());
        if (entity == null) {
            entity = entityService.createEntity(processedEntity);
            newEntities.add(entity.getClassName());
        }
        entityIdMappings.put(entity.getClassName(), entity.getId());
        entityService.updateRestOptions(entity.getId(), result.getRestProcessingResult());
        entityService.updateTracking(entity.getId(), result.getTrackingProcessingResult());
        entityService.addFields(entity, result.getFieldProcessingResult());
        entityService.addFilterableFields(entity, result.getUiFilterableProcessingResult());
        entityService.addDisplayedFields(entity, result.getUiDisplayableProcessingResult());
        entityService.updateSecurityOptions(entity.getId(), processedEntity.getSecurityMode(), processedEntity.getSecurityMembers(), processedEntity.getReadOnlySecurityMode(), processedEntity.getReadOnlySecurityMembers());
        entityService.updateMaxFetchDepth(entity.getId(), processedEntity.getMaxFetchDepth());
        entityService.addNonEditableFields(entity, result.getNonEditableProcessingResult());
    }
    for (Map.Entry<String, List<LookupDto>> entry : output.getLookupProcessorOutputs().entrySet()) {
        String entityClassName = entry.getKey();
        Long entityId = entityIdMappings.get(entityClassName);
        if (schemaComparator.lookupsDiffer(entityId, entry.getValue())) {
            entityService.addLookups(entityId, entry.getValue());
            if (!newEntities.contains(entityClassName)) {
                entityService.incrementVersion(entityId);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) EntityDto(org.motechproject.mds.dto.EntityDto) EntityProcessorOutput(org.motechproject.mds.annotations.internal.EntityProcessorOutput) MdsException(org.motechproject.mds.exception.MdsException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 EntityProcessorOutput (org.motechproject.mds.annotations.internal.EntityProcessorOutput)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 MDSProcessorOutput (org.motechproject.mds.annotations.internal.MDSProcessorOutput)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 MdsException (org.motechproject.mds.exception.MdsException)1 Bundle (org.osgi.framework.Bundle)1