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;
}
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;
}
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());
}
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));
}
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();
}
Aggregations