Search in sources :

Example 1 with SelectResult

use of org.motechproject.mds.web.SelectResult in project motech by motech.

the class EntityControllerTest method shouldReturnRecordsSortedByName.

@Test
public void shouldReturnRecordsSortedByName() throws Exception {
    List<EntityDto> expected = new ArrayList<>();
    expected.add(new EntityDto(9005L, "org.motechproject.appointments.api.model.Appointment", "MOTECH Appointments API", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9006L, "org.motechproject.ivr.domain.CallDetailRecord", "MOTECH IVR API", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9008L, "org.motechproject.messagecampaign.domain.campaign.Campaign", "MOTECH Message Campaign", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9001L, "org.motechproject.openmrs.ws.resource.model.Patient", "MOTECH OpenMRS Web Services", "navio", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9003L, "org.motechproject.openmrs.ws.resource.model.Patient", "MOTECH OpenMRS Web Services", "accra", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9002L, "org.motechproject.openmrs.ws.resource.model.Person", "MOTECH OpenMRS Web Services", "navio", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9004L, "org.motechproject.openmrs.ws.resource.model.Person", "MOTECH OpenMRS Web Services", "accra", SecurityMode.EVERYONE, null));
    expected.add(new EntityDto(9007L, "org.motechproject.mds.entity.Voucher", SecurityMode.EVERYONE, null));
    SelectResult expectedResult = new SelectResult(new SelectData(null, 1, 10), expected);
    controller.perform(get("/selectEntities").param("term", "").param("page", String.valueOf(1)).param("pageLimit", String.valueOf(10))).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expectedResult)));
}
Also used : SelectData(org.motechproject.mds.web.SelectData) EntityDto(org.motechproject.mds.dto.EntityDto) SelectResult(org.motechproject.mds.web.SelectResult) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 2 with SelectResult

use of org.motechproject.mds.web.SelectResult in project motech by motech.

the class AvailableController method getTypes.

@RequestMapping(value = "/available/types", method = RequestMethod.GET)
@ResponseBody
public SelectResult<TypeDto> getTypes(SelectData data) {
    List<TypeDto> list = typeService.getAllTypes();
    // The Long and Date types are available for DDEs exclusively
    list.remove(typeService.findType(Long.class));
    list.remove(typeService.findType(Date.class));
    list.remove(typeService.findType(Relationship.class));
    // The DateTime and LocalDate types from Joda are available for DDEs exclusively
    list.remove(typeService.findType(DateTime.class));
    list.remove(typeService.findType(org.joda.time.LocalDate.class));
    // TextArea type is available only from UI
    list.add(textAreaUIType());
    CollectionUtils.filter(list, new TypeMatcher(data.getTerm(), messageSource));
    Collections.sort(list, new TypeDisplayNameComparator(messageSource));
    return new SelectResult<>(data, list);
}
Also used : SelectResult(org.motechproject.mds.web.SelectResult) Relationship(org.motechproject.mds.domain.Relationship) TypeMatcher(org.motechproject.mds.web.matcher.TypeMatcher) TypeDisplayNameComparator(org.motechproject.mds.web.comparator.TypeDisplayNameComparator) TypeDto(org.motechproject.mds.dto.TypeDto) Date(java.util.Date) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with SelectResult

use of org.motechproject.mds.web.SelectResult in project motech by motech.

the class EntityController method getEntities.

@RequestMapping(value = "/selectEntities", method = RequestMethod.GET)
@PreAuthorize(Roles.HAS_DATA_OR_SCHEMA_ACCESS)
@ResponseBody
public SelectResult<EntityDto> getEntities(SelectData data) {
    List<EntityDto> list = entityService.listEntities();
    CollectionUtils.filter(list, new EntityMatcher(data.getTerm()));
    Collections.sort(list, new EntityNameComparator());
    return new SelectResult<>(data, list);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) SelectResult(org.motechproject.mds.web.SelectResult) EntityMatcher(org.motechproject.mds.web.matcher.EntityMatcher) EntityNameComparator(org.motechproject.mds.web.comparator.EntityNameComparator) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

SelectResult (org.motechproject.mds.web.SelectResult)3 EntityDto (org.motechproject.mds.dto.EntityDto)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 Relationship (org.motechproject.mds.domain.Relationship)1 TypeDto (org.motechproject.mds.dto.TypeDto)1 SelectData (org.motechproject.mds.web.SelectData)1 EntityNameComparator (org.motechproject.mds.web.comparator.EntityNameComparator)1 TypeDisplayNameComparator (org.motechproject.mds.web.comparator.TypeDisplayNameComparator)1 EntityMatcher (org.motechproject.mds.web.matcher.EntityMatcher)1 TypeMatcher (org.motechproject.mds.web.matcher.TypeMatcher)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1