Search in sources :

Example 1 with FormAttribute

use of org.kuali.kfs.datadictionary.FormAttribute in project cu-kfs by CU-CommunityApps.

the class LookupResource method doesAttrWithGivenNameExistForClass.

private boolean doesAttrWithGivenNameExistForClass(BusinessObjectEntry businessObjectEntry, String attributeName) {
    Class boClass = businessObjectEntry.getBusinessObjectClass();
    List<FormAttribute> attributeDefinitions = getLookupAttributeForClass(boClass);
    for (FormAttribute attributeDefn : attributeDefinitions) {
        if (attributeDefn.getName().equalsIgnoreCase(attributeName)) {
            return true;
        }
    }
    return false;
}
Also used : FormAttribute(org.kuali.kfs.datadictionary.FormAttribute)

Example 2 with FormAttribute

use of org.kuali.kfs.datadictionary.FormAttribute in project cu-kfs by CU-CommunityApps.

the class LookupResource method buildLookupControlValuesMap.

private Map<String, Object> buildLookupControlValuesMap(BusinessObjectEntry businessObjectEntry) {
    Class classForType = businessObjectEntry.getBusinessObjectClass();
    if (!isAuthorizedForLookup(classForType)) {
        throw new ForbiddenException();
    }
    Map<String, Object> valuesMap = new LinkedHashMap<>();
    List<FormAttribute> attributes = getLookupAttributeForClass(classForType);
    for (FormAttribute attribute : attributes) {
        Control control = attribute.getControl();
        if (control == null) {
            continue;
        }
        String singleAttributeName = attribute.getName();
        if (control.getType() == Control.Type.TREE) {
            // we have to do this bean resolution here b/c batch file (the only tree) is still a snowflake
            // and the DDD doesn't do the bean lookup for us (mainly b/c of the typing); hope to get rid of the
            // need for special VF type eventually
            String valuesFinderName = control.getValuesFinderName();
            if (StringUtils.isBlank(valuesFinderName)) {
                LOG.warn("A tree control without ValuesFinder name is most likely a mistake. BOE: " + businessObjectEntry.getName() + " attribute: " + singleAttributeName);
                continue;
            }
            HierarchicalControlValuesFinder valuesFinder = getDataDictionaryService().getDDBean(HierarchicalControlValuesFinder.class, valuesFinderName);
            if (valuesFinder == null) {
                LOG.warn("A tree control without a valid HierarchicalControlValuesFinder is most likely a " + "mistake. BOE:" + businessObjectEntry.getName() + " attribute: " + singleAttributeName);
                continue;
            }
            List<HierarchicalData> values = valuesFinder.getHierarchicalControlValues();
            valuesMap.put(singleAttributeName, values);
        } else {
            KeyValuesFinder valuesFinder = control.getValuesFinder();
            if (valuesFinder == null) {
                continue;
            }
            // CU Customization: keyValues list now comes from the helper method below.
            List<KeyValue> keyValues = getKeyValuesForLookup(valuesFinder);
            valuesMap.put(singleAttributeName, keyValues);
        }
    }
    return valuesMap;
}
Also used : HierarchicalControlValuesFinder(org.kuali.kfs.krad.keyvalues.HierarchicalControlValuesFinder) ForbiddenException(javax.ws.rs.ForbiddenException) ConcreteKeyValue(org.kuali.kfs.core.api.util.ConcreteKeyValue) KeyValue(org.kuali.kfs.core.api.util.KeyValue) HierarchicalData(org.kuali.kfs.krad.keyvalues.HierarchicalData) KeyValuesFinder(org.kuali.kfs.krad.keyvalues.KeyValuesFinder) FormAttribute(org.kuali.kfs.datadictionary.FormAttribute) LinkedHashMap(java.util.LinkedHashMap) Control(org.kuali.kfs.datadictionary.Control)

Example 3 with FormAttribute

use of org.kuali.kfs.datadictionary.FormAttribute in project cu-kfs by CU-CommunityApps.

the class LookupResource method getLookupAttributeForClass.

// todo move this to converter code
protected List<FormAttribute> getLookupAttributeForClass(Class classForType) {
    List<FormAttribute> attributes = getLookupDictionary().getLookupAttributes(classForType);
    attributes.forEach(attribute -> {
        final DefaultValueFinder defaultValueFinder = getDefaultValueFinderIfItExists(attribute);
        if (defaultValueFinder != null) {
            String defaultValue = defaultValueFinder.getDefaultValue();
            attribute.setDefaultValue(defaultValue);
        }
    });
    return attributes;
}
Also used : FormAttribute(org.kuali.kfs.datadictionary.FormAttribute) DefaultValueFinder(org.kuali.kfs.krad.valuefinder.DefaultValueFinder)

Example 4 with FormAttribute

use of org.kuali.kfs.datadictionary.FormAttribute 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

FormAttribute (org.kuali.kfs.datadictionary.FormAttribute)4 ForbiddenException (javax.ws.rs.ForbiddenException)2 LinkedHashMap (java.util.LinkedHashMap)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Response (javax.ws.rs.core.Response)1 ConcreteKeyValue (org.kuali.kfs.core.api.util.ConcreteKeyValue)1 KeyValue (org.kuali.kfs.core.api.util.KeyValue)1 Control (org.kuali.kfs.datadictionary.Control)1 Person (org.kuali.kfs.kim.api.identity.Person)1 AuthorizationException (org.kuali.kfs.krad.exception.AuthorizationException)1 HierarchicalControlValuesFinder (org.kuali.kfs.krad.keyvalues.HierarchicalControlValuesFinder)1 HierarchicalData (org.kuali.kfs.krad.keyvalues.HierarchicalData)1 KeyValuesFinder (org.kuali.kfs.krad.keyvalues.KeyValuesFinder)1 DefaultValueFinder (org.kuali.kfs.krad.valuefinder.DefaultValueFinder)1 SearchService (org.kuali.kfs.sys.businessobject.service.SearchService)1 LookupResponse (org.kuali.kfs.sys.rest.resource.responses.LookupResponse)1