Skip to content
Open
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 @@ -59,9 +59,9 @@
* <li> The property suffix {@link MCRXMappingClassificationGeneratorBase#EVALUATOR_KEY} can be used to
* specify the evaluator used to obtain category IDs from.
* <li> For the evaluator, the property suffix {@link MCRSentinel#DEFAULT_KEY} can be used to
* exclude the evaluator from the configuration and use a default {@link MCRSimpleXMappingEvaluator} instead.
* exclude the evaluator from the configuration and use a default {@link MCRSimpleXMappingEvaluator} instead.
* <li> The property suffix {@link MCRXMappingClassificationGeneratorBase#ON_MISSING_MAPPED_CATEGORY_KEY} can be used to
* specify the behaviour, when a mapped category ID is missing.
* specify the behavior, when a mapped category ID is missing.
* </ul>
* Example:
* <pre><code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

/**
* A {@link MCRXPathClassificationMappingCondition} is a {@link Condition} that
* determines the condition of a MyCoRe object based on a configurable X-Path evaluating the
* determines the condition of a MyCoRe object based on a configurable XPath evaluating the
* XML representation of the MyCoRe object.
* <p>
* The following configuration options are available:
* <ul>
* <li> The property suffix {@link MCRXPathClassificationMappingCondition#X_PATH_KEY} can be used to
* specify the X-Path to be used.
* specify the XPath to be used.
* </ul>
* Example:
* <pre><code>
Expand All @@ -53,7 +53,7 @@ public final class MCRXPathClassificationMappingCondition implements Condition {
private final String xPath;

public MCRXPathClassificationMappingCondition(String xPath) {
this.xPath = Objects.requireNonNull(xPath, "X-Path must not be null");
this.xPath = Objects.requireNonNull(xPath, "XPath must not be null");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
* <li> The property suffix {@link MCRXMappingClassificationGeneratorBase#EVALUATOR_KEY} can be used to
* specify the evaluator used to obtain category IDs from.
* <li> For the evaluator, the property suffix {@link MCRSentinel#DEFAULT_KEY} can be used to
* exclude the evaluator from the configuration and use a default {@link MCRSimpleXMappingEvaluator} instead.
* exclude the evaluator from the configuration and use a default {@link MCRSimpleXMappingEvaluator} instead.
* <li> The property suffix {@link MCRXMappingClassificationGeneratorBase#ON_MISSING_MAPPED_CATEGORY_KEY} can be used to
* specify the behaviour, when a mapped classification value is missing.
* specify the behavior, when a mapped classification value is missing.
* </ul>
* Example:
* <pre><code>
Expand Down
438 changes: 189 additions & 249 deletions mycore-pi/src/main/java/org/mycore/pi/MCRGenericPIGenerator.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.mycore.access.MCRAccessException;
import org.mycore.common.MCRException;
Expand All @@ -45,24 +44,32 @@ protected void handleObjectUpdated(MCREvent evt, MCRObject obj) {
private void processPIServices(MCRObject obj) {
List<MCRPIRegistrationInfo> registered = MCRPIManager.getInstance().getRegistered(obj);

final List<String> services = registered.stream().map(MCRPIRegistrationInfo::getService)
.collect(Collectors.toList());
final List<String> services = registered.stream().map(MCRPIRegistrationInfo::getService).toList();

List<MCRPIService<MCRPersistentIdentifier>> listOfServicesWithCreatablePIs = MCRPIServiceManager
.getInstance().getAutoCreationList().stream()
.filter(Predicate.not(s -> services.contains(s.getServiceID())))
.filter(Predicate.not(s -> MCRPIService.hasFlag(obj, "", s)))
.filter(s -> s.getCreationPredicate().test(obj))
.collect(Collectors.toList());
List<MCRPIService<MCRPersistentIdentifier>> autoCreatingPIServices = MCRPIServiceManager
.getInstance().getAutoCreationList();

listOfServicesWithCreatablePIs
.forEach((serviceToRegister) -> {
boolean mayCreatePI = true;
while (mayCreatePI) {

mayCreatePI = false;

List<MCRPIService<MCRPersistentIdentifier>> listOfServicesWithCreatablePIs = autoCreatingPIServices.stream()
.filter(Predicate.not(s -> services.contains(s.getServiceID())))
.filter(Predicate.not(s -> MCRPIService.hasFlag(obj, "", s)))
.filter(s -> s.getCreationPredicate().test(obj))
.toList();

for (MCRPIService<MCRPersistentIdentifier> serviceToRegister : listOfServicesWithCreatablePIs) {
try {
serviceToRegister.register(obj, "", false);
mayCreatePI = true;
} catch (MCRAccessException | MCRPersistentIdentifierException | ExecutionException
| InterruptedException e) {
throw new MCRException("Error while register pi for object " + obj.getId().toString(), e);
}
});
}
}

}
}
46 changes: 3 additions & 43 deletions mycore-pi/src/main/java/org/mycore/pi/MCRPIGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,19 @@

package org.mycore.pi;

import static org.mycore.pi.MCRPIService.GENERATOR_CONFIG_PREFIX;

import java.util.Map;

import org.mycore.common.config.MCRConfigurationException;
import org.mycore.common.config.annotation.MCRPostConstruction;
import org.mycore.common.config.annotation.MCRRawProperties;
import org.mycore.datamodel.metadata.MCRBase;
import org.mycore.pi.exceptions.MCRPersistentIdentifierException;

public abstract class MCRPIGenerator<T extends MCRPersistentIdentifier> {

private String generatorID;

private Map<String, String> properties;

public final Map<String, String> getProperties() {
return properties;
}

@MCRPostConstruction
public void init(String property) {
generatorID = property.substring(GENERATOR_CONFIG_PREFIX.length());
}

@MCRRawProperties(namePattern = "*", required = false)
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
public interface MCRPIGenerator<T extends MCRPersistentIdentifier> {

/**
* generates a {@link MCRPersistentIdentifier}
*
* @param mcrBase the mycore object for which the identifier is generated
* @param base the mycore object for which the identifier is generated
* @param additional additional information dedicated to the object like a mcrpath
* @return a unique persistence identifier
* @throws MCRPersistentIdentifierException if something goes wrong while generating
*/
public abstract T generate(MCRBase mcrBase, String additional) throws MCRPersistentIdentifierException;

/**
* checks if the property exists and throws a exception if not.
* @param propertyName to check
* @throws MCRConfigurationException if property does not exist
*/
protected void checkPropertyExists(final String propertyName) throws MCRConfigurationException {
if (!getProperties().containsKey(propertyName)) {
throw new MCRConfigurationException(
"Missing property " + GENERATOR_CONFIG_PREFIX + getGeneratorID() + "." + propertyName);
}
}
T generate(MCRBase base, String additional) throws MCRPersistentIdentifierException;

public String getGeneratorID() {
return generatorID;
}
}
25 changes: 25 additions & 0 deletions mycore-pi/src/main/java/org/mycore/pi/MCRPIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@ private static boolean matches(MCRPI flag, MCRPIService<?> piService, String add
&& Objects.equals(flag.getService(), piService.getServiceID());
}

public static boolean hasFlag(MCRBase obj, String additional, MCRPIService<?> piService, String type) {
MCRObjectService service = obj.getService();
List<String> flags = service.getFlags(PI_FLAG);
Gson gson = getGson();
return flags.stream()
.map(s -> gson.fromJson(s, MCRPI.class))
.anyMatch(flag -> matches(flag, piService, type, additional));
}

public static List<MCRPI> getFlags(MCRBase obj, String additional, MCRPIService<?> piService, String type) {
MCRObjectService service = obj.getService();
List<String> flags = service.getFlags(PI_FLAG);
Gson gson = getGson();
return flags.stream()
.map(s -> gson.fromJson(s, MCRPI.class))
.filter(flag -> matches(flag, piService, type, additional))
.toList();
}

private static boolean matches(MCRPI flag, MCRPIService<?> piService, String type, String additional) {
return flag.getAdditional().equals(additional)
&& Objects.equals(flag.getService(), piService.getServiceID())
&& Objects.equals(flag.getType(), type);
}

public static void updateFlagsInDatabase(MCRBase obj) {
Gson gson = getGson();
obj.getService().getFlags(PI_FLAG).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import org.mycore.common.config.annotation.MCRProperty;
import org.mycore.datamodel.metadata.MCRBase;
import org.mycore.pi.MCRPIManager;
import org.mycore.pi.MCRPIService;
import org.mycore.pi.MCRPIServiceManager;
import org.mycore.pi.MCRPersistentIdentifier;

/**
* PI Predicate, that checks if another PersistentIdentifier was created within the PI component
Expand Down Expand Up @@ -49,7 +51,12 @@ public class MCRPIOtherPICreatedPredicate extends MCRPIPredicateBase

@Override
public boolean test(MCRBase mcrBase) {
return MCRPIManager.getInstance().isCreated(mcrBase.getId(), "", type, service);

MCRPIServiceManager serviceManager = MCRPIServiceManager.getInstance();
MCRPIService<MCRPersistentIdentifier> service = serviceManager.getRegistrationService(this.service);

return MCRPIService.hasFlag(mcrBase, "", service, this.type);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

import org.mycore.common.config.annotation.MCRProperty;
import org.mycore.datamodel.metadata.MCRBase;
import org.mycore.pi.MCRPIManager;
import org.mycore.pi.MCRPIService;
import org.mycore.pi.MCRPIServiceManager;
import org.mycore.pi.MCRPersistentIdentifier;
import org.mycore.pi.backend.MCRPI;

/**
* PI Predicate, that checks if another PersistentIdentifier was registered within the PI component
Expand Down Expand Up @@ -49,7 +52,18 @@ public class MCRPIOtherPIRegisteredPredicate extends MCRPIPredicateBase

@Override
public boolean test(MCRBase mcrBase) {
return MCRPIManager.getInstance().isRegistered(mcrBase.getId(), "", type, service);

MCRPIServiceManager serviceManager = MCRPIServiceManager.getInstance();
MCRPIService<MCRPersistentIdentifier> service = serviceManager.getRegistrationService(this.service);

for (MCRPI pi : MCRPIService.getFlags(mcrBase, "", service, this.type)) {
if (pi.getRegistered() != null) {
return true;
}
}

return false;

}

}
Loading
Loading