use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class LookupProcessorTest method shouldProcessMethodWithRestExposedAnnotation.
@Test
public void shouldProcessMethodWithRestExposedAnnotation() throws Exception {
when(paranamer.lookupParameterNames(getTestMethodExposedViaRest())).thenReturn(argNames);
EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(new FieldDto("aaa", "bbb", TypeDto.STRING)));
lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
Method method = getTestMethodExposedViaRest();
LookupDto dto = new LookupDto("Test Method Exposed Via Rest", true, true, lookupFieldDtos(argNames), true, "testMethodExposedViaRest", asList(argNames), true);
lookupProcessor.process(method);
Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
assertTrue(elements.containsKey(TEST_CLASS_NAME));
List<LookupDto> list = elements.get(TEST_CLASS_NAME);
assertEquals(1, list.size());
assertEquals(dto, list.get(0));
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class MdsRestFacadeImpl method readLookups.
private void readLookups(EntityInfo entity) {
for (LookupDto lookup : entity.getLookups()) {
Map<String, FieldDto> fieldMap = getLookupFieldsMapping(entity, lookup);
String lookuMethodpName = lookup.getMethodName();
if (lookup.isExposedViaRest()) {
// we create executors for exposed lookups
LookupExecutor executor = new LookupExecutor(dataService, lookup, fieldMap);
lookupExecutors.put(lookuMethodpName, executor);
} else {
// we keep a list of forbidden lookups in order to print the appropriate error
forbiddenLookupMethodNames.add(lookuMethodpName);
}
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityInfrastructureBuilderImpl method getInterfaceCode.
private byte[] getInterfaceCode(String interfaceClassName, String className, EntityDto entity, SchemaHolder schemaHolder) {
try {
// the interface can come from the developer for DDE, but it doesn't have to
// in which case it will be generated from scratch
CtClass superInterface = null;
if (null != entity && MotechClassPool.isServiceInterfaceRegistered(className)) {
String ddeInterfaceName = MotechClassPool.getInterfaceName(className);
Bundle declaringBundle = MdsBundleHelper.searchForBundle(bundleContext, entity);
if (declaringBundle == null) {
LOGGER.error("Unable to find bundle declaring the DDE interface for {}", className);
} else {
superInterface = JavassistUtil.loadClass(declaringBundle, ddeInterfaceName, classPool);
}
}
// standard super interface - MotechDataService, for EUDE or DDE without an interface
if (superInterface == null) {
superInterface = classPool.getCtClass(MotechDataService.class.getName());
superInterface.setGenericSignature(getGenericSignature(className));
}
CtClass interfaceClass = createOrRetrieveInterface(interfaceClassName, superInterface);
List<CtMethod> methods = new ArrayList<>();
// a count method for the lookup
if (null != entity) {
List<LookupDto> lookups = schemaHolder.getLookups(entity);
for (LookupDto lookup : lookups) {
for (LookupType lookupType : LookupType.values()) {
LookupBuilder lookupBuilder = new LookupBuilder(entity, lookup, interfaceClass, lookupType, schemaHolder);
methods.add(lookupBuilder.buildSignature());
}
}
}
// clear lookup methods before adding the new ones
removeExistingMethods(interfaceClass);
for (CtMethod method : methods) {
interfaceClass.addMethod(method);
}
return interfaceClass.toBytecode();
} catch (NotFoundException | IOException | CannotCompileException e) {
throw new EntityInfrastructureException(interfaceClassName, e);
}
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class MdsRestBundleIT method prepareEntity.
private void prepareEntity() throws IOException {
EntityDto entityDto = new EntityDto(ENTITY_NAME);
entityDto = entityService.createEntity(entityDto);
FieldDto strField = new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("strFieldDisp", "strField", true, false), false, null);
FieldDto intField = new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("intFieldDisp", "intField"), false, null);
entityService.addFields(entityDto, asList(strField, intField));
RestOptionsDto restOptions = new RestOptionsDto(true, true, true, true, false);
restOptions.setFieldNames(prepareAllRestFieldNames(entityService.getEntityFields(entityDto.getId())));
entityService.updateRestOptions(entityDto.getId(), restOptions);
// a set based lookup for our convenience
LookupFieldDto intSetLookupField = new LookupFieldDto(null, "intField", LookupFieldType.SET);
LookupDto setLookup = new LookupDto("byIntSet", false, true, asList(intSetLookupField), false);
// list return REST lookup
LookupFieldDto intLookupField = new LookupFieldDto(null, "intField", LookupFieldType.VALUE);
LookupDto listLookup = new LookupDto("byInt", false, true, asList(intLookupField), false);
// single return REST lookup
LookupFieldDto strLookupField = new LookupFieldDto(null, "strField", LookupFieldType.VALUE);
LookupDto singleLookup = new LookupDto("byStr", true, true, asList(strLookupField), false);
entityService.addLookups(entityDto.getId(), asList(setLookup, listLookup, singleLookup));
}
Aggregations