Skip to content

Commit

Permalink
Fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Oct 2, 2024
1 parent a2f15f4 commit 5bba94b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.jms.JMSException;

import org.apache.commons.lang3.tuple.Pair;
import org.kitodo.api.MdSec;
import org.kitodo.api.Metadata;
import org.kitodo.api.MetadataEntry;
import org.kitodo.api.MetadataGroup;
Expand Down Expand Up @@ -116,7 +117,7 @@ public class CreateNewProcessOrder {
this.imports = convertImports(ticket.getList(FIELD_IMPORT));
this.title = Optional.ofNullable(ticket.getString(FIELD_TITLE));
this.parentId = Optional.ofNullable(convertProcessId(ticket.getString(FIELD_PARENT)));
this.metadata = convertMetadata(ticket.getMapOfString(FIELD_METADATA));
this.metadata = convertMetadata(ticket.getMapOfString(FIELD_METADATA), MdSec.DMD_SEC);
}

/**
Expand Down Expand Up @@ -189,7 +190,7 @@ private static final Integer convertProcessId(String processId) throws DataExcep
* Converts metadata details into safe data objects. For {@code null}, it
* will return an empty collection, never {@code null}.
*/
private static final HashSet<Metadata> convertMetadata(@Nullable Map<?, ?> metadata) {
private static final HashSet<Metadata> convertMetadata(@Nullable Map<?, ?> metadata, @Nullable MdSec domain) {

HashSet<Metadata> result = new HashSet<>();
if (Objects.isNull(metadata)) {
Expand All @@ -211,12 +212,14 @@ private static final HashSet<Metadata> convertMetadata(@Nullable Map<?, ?> metad
if (dubiousValue instanceof Map) {
MetadataGroup metadataGroup = new MetadataGroup();
metadataGroup.setKey(key);
metadataGroup.setMetadata(convertMetadata((Map<?, ?>) dubiousValue));
metadataGroup.setMetadata(convertMetadata((Map<?, ?>) dubiousValue, null));
metadataGroup.setDomain(domain);
result.add(metadataGroup);
} else {
MetadataEntry metadataEntry = new MetadataEntry();
metadataEntry.setKey(key);
metadataEntry.setValue(dubiousValue.toString());
metadataEntry.setDomain(domain);
result.add(metadataEntry);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ public String getMandatoryString(String key) throws JMSException {
return mandatoryString;
}

/**
* Fetches a String from a map. This is a strict implementation that
* requires the string not to be null and not to be empty.
*
* @param key
* the name of the string to return
* @return the string requested
* @throws IllegalArgumentException
* in case that get returns null, an inappropriate object, or
* the returned string is of length “0”.
*/
public static String getMandatoryString(Map<?, ?> data, String key) {
Object value = data.get(key);
if (Objects.isNull(value)) {
throw new IllegalArgumentException(MISSING_ARGUMENT + key + "\"");
}
if (!(value instanceof String)) {
throw new IllegalArgumentException(MANDATORY_ARGUMENT + key + " is not a string");
}
String mandatoryString = (String) value;
if (mandatoryString.isEmpty()) {
throw new IllegalArgumentException(MISSING_ARGUMENT + key + "\"");
}
return mandatoryString;
}

/**
* Fetches a {@code Collection<Integer>} from a MapMessage. This is a loose
* implementation for an optional object with optional content. The
Expand Down Expand Up @@ -163,32 +189,6 @@ public Collection<String> getCollectionOfString(String key) throws JMSException
.collect(Collectors.toList());
}

/**
* Fetches a String from a map. This is a strict implementation that
* requires the string not to be null and not to be empty.
*
* @param key
* the name of the string to return
* @return the string requested
* @throws IllegalArgumentException
* in case that get returns null, an inappropriate object, or
* the returned string is of length “0”.
*/
public static String getMandatoryString(Map<?, ?> data, String key) {
Object value = data.get(key);
if (Objects.isNull(value)) {
throw new IllegalArgumentException(MISSING_ARGUMENT + key + "\"");
}
if (!(value instanceof String)) {
throw new IllegalArgumentException(MANDATORY_ARGUMENT + key + " is not a string");
}
String mandatoryString = (String) value;
if (mandatoryString.isEmpty()) {
throw new IllegalArgumentException(MISSING_ARGUMENT + key + "\"");
}
return mandatoryString;
}

/**
* Fetches a String from a MapMessage. This is an access forward to the
* native function of the MapMessage. You may consider to use
Expand Down

0 comments on commit 5bba94b

Please sign in to comment.