Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding metadata to metadata groups #4550

Merged
merged 2 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class NestedKeyView<D extends KeyDeclaration> extends AbstractKeyView<D> impleme
* When the API caller tries to add a field that does not exist
* in the ruleset.
*/
private static final <V> void addFieldsForAdditionallySelectedKeys(Collection<String> additionallySelectedKeys,
LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable) {
private static <V> void addFieldsForAdditionallySelectedKeys(Collection<String> additionallySelectedKeys,
LinkedHashMap<String,
AuxiliaryTableRow> auxiliaryTable) {

additionallySelectedKeys.parallelStream().map(auxiliaryTable::get)
.forEach(AuxiliaryTableRow::addOneAdditionalField);
Expand All @@ -78,8 +79,8 @@ private static final <V> void addFieldsForAdditionallySelectedKeys(Collection<St
* @param auxiliaryTable
* auxiliary table to append to
*/
private static final void appendRowsToAuxiliaryTable(Collection<AuxiliaryTableRow> rows,
LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable) {
private static void appendRowsToAuxiliaryTable(Collection<AuxiliaryTableRow> rows,
LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable) {

for (AuxiliaryTableRow auxiliaryTableRow : rows) {
auxiliaryTable.put(auxiliaryTableRow.getId(), auxiliaryTableRow);
Expand All @@ -100,7 +101,7 @@ private static final void appendRowsToAuxiliaryTable(Collection<AuxiliaryTableRo
* the wish list of the user’s preferred human language
* @return sorted list of fields
*/
private static final <V> Collection<AuxiliaryTableRow> sort(
private static <V> Collection<AuxiliaryTableRow> sort(
HashMap<String, AuxiliaryTableRow> auxiliaryTableToBeSorted, List<LanguageRange> priorityList) {

TreeMap<String, AuxiliaryTableRow> sorted = new TreeMap<>();
Expand Down Expand Up @@ -190,7 +191,7 @@ protected NestedKeyView(Ruleset ruleset, D divisionDeclaration, Rule rule, Setti
* @param auxiliaryTable
* auxiliary table
*/
private final <V> void addAnyRules(LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable) {
private void addAnyRules(LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable) {

auxiliaryTable.entrySet().parallelStream().forEach(entry -> entry.getValue()
.setRule(rule.getRuleForKey(entry.getKey(), division)));
Expand All @@ -199,7 +200,7 @@ private final <V> void addAnyRules(LinkedHashMap<String, AuxiliaryTableRow> auxi
/**
* Adds the keys selected by the user to be added to the list of keys to
* add. This procedure is a part of the function to
* {@link #cerateAuxiliaryTableWithKeysToBeSorted(LinkedHashMap, Rule, Collection, Collection)}.
* {@link #createAuxiliaryTableWithKeysToBeSorted(LinkedHashMap, Rule, Collection, Collection)}.
*
* @param auxiliaryTable
* the target table. If the key is already here, it will not be
Expand All @@ -211,15 +212,15 @@ private final <V> void addAnyRules(LinkedHashMap<String, AuxiliaryTableRow> auxi
* @param toBeSorted
* write access to the list of keys to be sorted
*/
private final <V> void addAdditionalKeys(LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable,
Rule rule, Collection<String> additionalKeys,
HashMap<String, AuxiliaryTableRow> toBeSorted) {
private void addAdditionalKeys(LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable,
Rule rule, Collection<String> additionalKeys,
HashMap<String, AuxiliaryTableRow> toBeSorted) {
for (String additionalKey : additionalKeys) {
if (!auxiliaryTable.containsKey(additionalKey) && !toBeSorted.containsKey(additionalKey)) {
Optional<Key> optionalKey = rule.isUnspecifiedUnrestricted() ? Optional.empty()
: ruleset.getKey(additionalKey);
KeyDeclaration keyDeclaration = optionalKey.isPresent() ? new KeyDeclaration(ruleset, optionalKey.get())
: new KeyDeclaration(ruleset, additionalKey);
KeyDeclaration keyDeclaration = optionalKey.map(key -> new KeyDeclaration(ruleset, key))
.orElseGet(() -> new KeyDeclaration(ruleset, additionalKey));
toBeSorted.put(additionalKey, new AuxiliaryTableRow(keyDeclaration, settings));
}
}
Expand All @@ -228,7 +229,7 @@ private final <V> void addAdditionalKeys(LinkedHashMap<String, AuxiliaryTableRow
/**
* If the rule is unspecified unrestricted, the remaining keys are added to
* the keys to be sorted. This procedure is a part of the function to
* {@link #cerateAuxiliaryTableWithKeysToBeSorted(LinkedHashMap, Rule, Collection, Collection)}.
* {@link #createAuxiliaryTableWithKeysToBeSorted(LinkedHashMap, Rule, Collection, Collection)}.
*
* @param auxiliaryTable
* the target table. If the key is already here, it will not be
Expand All @@ -238,8 +239,9 @@ private final <V> void addAdditionalKeys(LinkedHashMap<String, AuxiliaryTableRow
* @param toBeSorted
* write access to the list of keys to be sorted
*/
private final <V> void addRemainingKeys(LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable,
Collection<KeyDeclaration> keyDeclarations, HashMap<String, AuxiliaryTableRow> toBeSorted) {
private void addRemainingKeys(LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable,
Collection<KeyDeclaration> keyDeclarations,
HashMap<String, AuxiliaryTableRow> toBeSorted) {
for (KeyDeclaration keyDeclaration : keyDeclarations) {
if (!auxiliaryTable.containsKey(keyDeclaration.getId())) {
toBeSorted.put(keyDeclaration.getId(), new AuxiliaryTableRow(keyDeclaration, settings));
Expand Down Expand Up @@ -268,7 +270,7 @@ private final <V> void addRemainingKeys(LinkedHashMap<String, AuxiliaryTableRow>
* which keys the user has additionally selected
* @return an auxiliary table for additional keys yet to be sorted
*/
private final <V> HashMap<String, AuxiliaryTableRow> cerateAuxiliaryTableWithKeysToBeSorted(
private HashMap<String, AuxiliaryTableRow> createAuxiliaryTableWithKeysToBeSorted(
LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable, Rule rule,
Collection<KeyDeclaration> keyDeclarations, Collection<String> additionalKeys) {

Expand Down Expand Up @@ -297,7 +299,7 @@ private Collection<AuxiliaryTableRow> createAuxiliaryTable(Collection<Metadata>

LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable = createAuxiliaryTableWithPreSortedKeys(
rule.getExplicitlyPermittedKeys(declaration));
HashMap<String, AuxiliaryTableRow> auxiliaryTableToBeSorted = cerateAuxiliaryTableWithKeysToBeSorted(
HashMap<String, AuxiliaryTableRow> auxiliaryTableToBeSorted = createAuxiliaryTableWithKeysToBeSorted(
auxiliaryTable, rule, declaration.getKeyDeclarations(), additionalKeys);
storeValues(currentEntries, auxiliaryTable, auxiliaryTableToBeSorted);
appendRowsToAuxiliaryTable(sort(auxiliaryTableToBeSorted, priorityList), auxiliaryTable);
Expand All @@ -315,7 +317,7 @@ private Collection<AuxiliaryTableRow> createAuxiliaryTable(Collection<Metadata>
* keys given in their order by the restriction rule
* @return the auxiliary table
*/
private final <V> LinkedHashMap<String, AuxiliaryTableRow> createAuxiliaryTableWithPreSortedKeys(
private LinkedHashMap<String, AuxiliaryTableRow> createAuxiliaryTableWithPreSortedKeys(
List<KeyDeclaration> explicitlyPermittedKeys) {

LinkedHashMap<String, AuxiliaryTableRow> auxiliaryTable = new LinkedHashMap<>();
Expand Down Expand Up @@ -373,9 +375,8 @@ public Collection<MetadataViewInterface> getAllowedMetadata() {
* @return metadata view
*/
private MetadataViewInterface rowToView(AuxiliaryTableRow row) {
MetadataViewInterface view = row.isComplexKey() ? getNestedKeyView(row.getId())
return row.isComplexKey() ? getNestedKeyView(row.getId())
: new KeyView(row.getKey(), rule.getRuleForKey(row.getId(), division), settings, priorityList);
return view;
}

/**
Expand Down Expand Up @@ -446,9 +447,9 @@ public List<MetadataViewWithValuesInterface> getSortedVisibleMetadata(Collection
* @param auxiliaryTableToBeSorted
* help table with rows that still have to be sorted
*/
private final void storeValues(Collection<Metadata> enteredMetaData,
LinkedHashMap<String, AuxiliaryTableRow> sortedAuxiliaryTable,
HashMap<String, AuxiliaryTableRow> auxiliaryTableToBeSorted) {
private void storeValues(Collection<Metadata> enteredMetaData,
LinkedHashMap<String, AuxiliaryTableRow> sortedAuxiliaryTable,
HashMap<String, AuxiliaryTableRow> auxiliaryTableToBeSorted) {

for (Metadata metadata : enteredMetaData) {
String keyId = metadata.getKey();
Expand All @@ -463,9 +464,9 @@ private final void storeValues(Collection<Metadata> enteredMetaData,
}

private AuxiliaryTableRow retrieveOrCompute(String keyId) {
Optional<Key> possibleKey = ruleset.getKey(keyId);
KeyDeclaration keyDeclaration = possibleKey.isPresent() ? new KeyDeclaration(ruleset, possibleKey.get(), true)
: new KeyDeclaration(ruleset, keyId);
Optional<KeyDeclaration> optionalKeyDeclaration = super.declaration.getKeyDeclarations().parallelStream()
.filter(childKeyDeclaration -> keyId.equals(childKeyDeclaration.getId())).findAny();
KeyDeclaration keyDeclaration = optionalKeyDeclaration.orElseGet(() -> new KeyDeclaration(ruleset, keyId));
return new AuxiliaryTableRow(keyDeclaration, settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ public List<TaskDTO> getCurrentTasksForUser(ProcessDTO processDTO) {
}

/**
* Gets the amount of processes for the current filter
* Gets the amount of processes for the current filter.
* @return amount of processes
*/
public String getAmount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,15 @@ public Collection<Metadata> getMetadata() throws InvalidMetadataValueException {
return Collections.singletonList(result);
}

/**
* Return this ProcessFieldedMetadata as MetadataGroup.
*
* @return MetadataGroup representing this ProcessFieldedMetadata
*/
public Collection<Metadata> getChildMetadata() {
return metadata;
}

/**
* Returns the rows that JSF has to display.
*
Expand Down Expand Up @@ -568,4 +577,22 @@ public void setMetadata(Collection<Metadata> metadata) {
treeNode.setExpanded(true);
createMetadataTable();
}

/**
* Get metadataView.
*
* @return value of metadataView
*/
public ComplexMetadataViewInterface getMetadataView() {
return metadataView;
}

/**
* Get additionallySelectedFields.
*
* @return value of additionallySelectedFields
*/
public Collection<String> getAdditionallySelectedFields() {
return additionallySelectedFields;
}
}
Loading