Search in sources :

Example 61 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityController method getEntitiesByModule.

@RequestMapping(value = "/entities/byModule", method = RequestMethod.GET)
@ResponseBody
public Map<String, List<EntityDto>> getEntitiesByModule() {
    Map<String, List<EntityDto>> byModule = new LinkedHashMap<>();
    List<EntityDto> entities = entityService.listEntities(true);
    for (EntityDto entity : entities) {
        if (entity.getModule() == null) {
            if (!byModule.containsKey(NO_MODULE)) {
                byModule.put(NO_MODULE, new ArrayList<EntityDto>());
            }
            EntityDto entityDto = new EntityDto();
            entityDto.setNonEditable(entity.isNonEditable());
            entityDto.setReadOnlyAccess(entity.isReadOnlyAccess());
            entityDto.setName(entity.getName());
            byModule.get(NO_MODULE).add(entityDto);
        } else {
            if (!byModule.containsKey(entity.getModule())) {
                byModule.put(entity.getModule(), new ArrayList<EntityDto>());
            }
            if (!entity.isAbstractClass()) {
                EntityDto entityDto = new EntityDto();
                entityDto.setNonEditable(entity.isNonEditable());
                entityDto.setReadOnlyAccess(entity.isReadOnlyAccess());
                entityDto.setName(entity.getName());
                byModule.get(entity.getModule()).add(entityDto);
            }
        }
    }
    return byModule;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 62 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityController method getEntityByModuleAndEntityName.

@RequestMapping(value = "/entities/getEntity/{module}/{entityName}", method = RequestMethod.GET)
@PreAuthorize(Roles.HAS_DATA_OR_SCHEMA_ACCESS)
@ResponseBody
public EntityDto getEntityByModuleAndEntityName(@PathVariable String module, @PathVariable String entityName) {
    List<EntityDto> entities = getAllEntities();
    String moduleName = module.equals(NO_MODULE) ? null : module;
    for (EntityDto entity : entities) {
        if (entity.getModule() == null && moduleName == null && entity.getName().equals(entityName)) {
            return entity;
        } else if (entity.getModule() != null && entity.getModule().equals(moduleName) && entity.getName().equals(entityName)) {
            return entity;
        }
    }
    return null;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityController method saveEntity.

@RequestMapping(value = "/entities", method = RequestMethod.POST)
@PreAuthorize(Roles.HAS_SCHEMA_ACCESS)
@ResponseBody
public EntityDto saveEntity(@RequestBody EntityDto entity) throws IOException, IllegalAccessException, ClassNotFoundException, InstantiationException {
    EntityDto created = entityService.createEntity(entity);
    mdsBundleRegenerationService.regenerateMdsDataBundle();
    return entityService.getEntityForEdit(created.getId());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 64 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class MdsLookupServiceImpl method buildLookupExecutor.

private LookupExecutor buildLookupExecutor(String entityClassName, String lookupName) {
    String fullyQualifiedEntityClassName;
    if (entityClassName.contains(".")) {
        fullyQualifiedEntityClassName = entityClassName;
    } else {
        fullyQualifiedEntityClassName = Constants.PackagesGenerated.ENTITY + "." + entityClassName;
    }
    MotechDataService dataService = OSGiServiceUtils.findService(bundleContext, MotechClassPool.getInterfaceName(fullyQualifiedEntityClassName));
    EntityDto entity = entityService.getEntityByClassName(fullyQualifiedEntityClassName);
    LookupDto lookup = entityService.getLookupByName(entity.getId(), lookupName);
    return new LookupExecutor(dataService, lookup, entityService.getLookupFieldsMapping(entity.getId(), lookupName));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) LookupExecutor(org.motechproject.mds.lookup.LookupExecutor) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 65 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceLifecycleListenerProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    processor = new InstanceLifecycleListenerProcessor();
    processor.setJdoListenerRegistryService(jdoListenerRegistryService);
    jdoListenerRegistryService.setEntityService(entityService);
    File file = computeTestDataRoot(getClass());
    String location = file.toURI().toURL().toString();
    doReturn(location).when(bundle).getLocation();
    doReturn(Sample.class).when(bundle).loadClass(Sample.class.getName());
    doReturn(Arrays.asList(new EntityDto("org.motechproject.Test"))).when(entityService).findEntitiesByPackage(anyString());
    setUpMockBundle();
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Sample(org.motechproject.mds.annotations.internal.samples.Sample) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) Before(org.junit.Before)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6