Search in sources :

Example 1 with HierarchicalData

use of org.kuali.kfs.krad.keyvalues.HierarchicalData 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 2 with HierarchicalData

use of org.kuali.kfs.krad.keyvalues.HierarchicalData in project cu-kfs by CU-CommunityApps.

the class BatchFileDirectoryServiceImpl method children.

private Stream<Path> children(Path path, HierarchicalData hierarchicalData) {
    if (Files.isDirectory(path)) {
        try {
            String fileName = path.getFileName().toString();
            String relativePath = BatchFileUtils.pathRelativeToRootDirectory(path.toString());
            HierarchicalData subTreeData = new HierarchicalData(fileName, relativePath);
            hierarchicalData.addChild(subTreeData);
            return Files.list(path).sorted().flatMap(filePath -> children(filePath, subTreeData));
        } catch (Exception e) {
            return Stream.empty();
        }
    } else {
        return Stream.of(path);
    }
}
Also used : HierarchicalData(org.kuali.kfs.krad.keyvalues.HierarchicalData)

Example 3 with HierarchicalData

use of org.kuali.kfs.krad.keyvalues.HierarchicalData in project cu-kfs by CU-CommunityApps.

the class BatchFileDirectoryServiceImpl method buildBatchFileLookupDirectoriesHierarchy.

@Override
@Cacheable(cacheNames = BatchFile.CACHE_NAME, key = "'getHierarchicalControlValues'")
public List<HierarchicalData> buildBatchFileLookupDirectoriesHierarchy() {
    List<HierarchicalData> hierarchicalData = new LinkedList<>();
    List<File> rootDirectories = BatchFileUtils.retrieveBatchFileLookupRootDirectories();
    rootDirectories.sort(Comparator.comparing(File::getName));
    for (File rootDirectory : rootDirectories) {
        if (rootDirectory.isDirectory()) {
            String directoryName = rootDirectory.getName();
            HierarchicalData dataForThisDirTree = new HierarchicalData(directoryName, directoryName);
            // TODO it needs a terminal stream operator to work but I don't know what kind needs to go there
            // hence the count
            children(rootDirectory.toPath(), dataForThisDirTree).count();
            // couldn't figure out how to not have fake root (children would get null first time); this was an easy
            // work around that shouldn't cost much
            hierarchicalData.add(dataForThisDirTree.getChildren().get(0));
        }
    }
    return hierarchicalData;
}
Also used : HierarchicalData(org.kuali.kfs.krad.keyvalues.HierarchicalData) BatchFile(org.kuali.kfs.sys.batch.BatchFile) File(java.io.File) LinkedList(java.util.LinkedList) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

HierarchicalData (org.kuali.kfs.krad.keyvalues.HierarchicalData)3 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 ForbiddenException (javax.ws.rs.ForbiddenException)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 FormAttribute (org.kuali.kfs.datadictionary.FormAttribute)1 HierarchicalControlValuesFinder (org.kuali.kfs.krad.keyvalues.HierarchicalControlValuesFinder)1 KeyValuesFinder (org.kuali.kfs.krad.keyvalues.KeyValuesFinder)1 BatchFile (org.kuali.kfs.sys.batch.BatchFile)1 Cacheable (org.springframework.cache.annotation.Cacheable)1