Search in sources :

Example 1 with LookupResponse

use of org.kuali.kfs.sys.rest.resource.responses.LookupResponse in project cu-kfs by CU-CommunityApps.

the class LookupResource method getLookup.

@GET
public Response getLookup() {
    Class classForType = businessObjectEntry.getBusinessObjectClass();
    if (!isAuthorizedForLookup(classForType)) {
        Person user = getUserSessionFromRequest(this.servletRequest).getPerson();
        AuthorizationException authorizationException = new AuthorizationException(user.getPrincipalName(), "lookup", classForType.getName());
        Response.ResponseBuilder responseBuilder = Response.status(Response.Status.FORBIDDEN);
        responseBuilder.entity(authorizationException);
        throw new ForbiddenException(responseBuilder.build());
    }
    List<FormAttribute> lookupAttributes = getLookupAttributeForClass(classForType);
    for (FormAttribute lookupAttribute : lookupAttributes) {
        setNestedLookupFields(lookupAttribute, classForType);
    }
    String title = getLookupDictionary().getLookupTitle(classForType);
    if (StringUtils.isEmpty(title)) {
        title = businessObjectEntry.getObjectLabel() + " Lookup";
    }
    SearchService searchService = getLookupDictionary().getSearchService(classForType);
    if (searchService == null) {
        LOG.error(businessObjectEntry.getName() + " seems to be missing a SearchService! A lookup cannot " + "be queried without a SearchService.");
        throw new InternalServerErrorException("The requested lookup is currently unavailable.");
    }
    LookupResponse.Create create = null;
    if (shouldCreateNewUrlBeIncluded(classForType)) {
        create = getCreateBlock(classForType);
    }
    LookupResponse.Results results = new LookupResponse.Results(searchService.getSearchResultsAttributes(classForType), getBusinessObjectDictionaryService().getLookupDefaultSortFieldNames(classForType));
    LookupResponse lookupResponse = new LookupResponse(title, lookupAttributes, create, results);
    return Response.ok(lookupResponse).build();
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) AuthorizationException(org.kuali.kfs.krad.exception.AuthorizationException) FormAttribute(org.kuali.kfs.datadictionary.FormAttribute) LookupResponse(org.kuali.kfs.sys.rest.resource.responses.LookupResponse) Response(javax.ws.rs.core.Response) LookupResponse(org.kuali.kfs.sys.rest.resource.responses.LookupResponse) SearchService(org.kuali.kfs.sys.businessobject.service.SearchService) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Person(org.kuali.kfs.kim.api.identity.Person) GET(javax.ws.rs.GET)

Aggregations

ForbiddenException (javax.ws.rs.ForbiddenException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Response (javax.ws.rs.core.Response)1 FormAttribute (org.kuali.kfs.datadictionary.FormAttribute)1 Person (org.kuali.kfs.kim.api.identity.Person)1 AuthorizationException (org.kuali.kfs.krad.exception.AuthorizationException)1 SearchService (org.kuali.kfs.sys.businessobject.service.SearchService)1 LookupResponse (org.kuali.kfs.sys.rest.resource.responses.LookupResponse)1