Skip to content
Open
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
52 changes: 52 additions & 0 deletions src/main/java/de/urmel_dl/dbt/rc/persistency/SlotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.mycore.access.MCRAccessException;
import org.mycore.access.MCRAccessManager;
Expand All @@ -48,6 +49,7 @@
import org.mycore.common.MCRUserInformation;
import org.mycore.common.content.MCRContent;
import org.mycore.datamodel.classifications2.MCRCategoryID;
import org.mycore.datamodel.classifications2.impl.MCRCategoryDAOImpl;
import org.mycore.datamodel.common.MCRAbstractMetadataVersion;
import org.mycore.datamodel.common.MCRActiveLinkException;
import org.mycore.datamodel.common.MCRCreatorCache;
Expand Down Expand Up @@ -76,6 +78,7 @@
import de.urmel_dl.dbt.rc.datamodel.slot.SlotList;
import de.urmel_dl.dbt.rc.datamodel.slot.entries.FileEntry;
import de.urmel_dl.dbt.rc.utils.SlotWrapper;
import de.urmel_dl.dbt.utils.EntityFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
Expand Down Expand Up @@ -242,6 +245,55 @@ public static void setOwner(final String objId, final MCRUserInformation user)
MCRCreatorCache.invalidate(objId);
}

/**
* Checks if given access key was previously used on slot.
* <p>
* Called from XEditor via <code>xed:call-java</code> (content/rc/slot-includes.xed).
*
* @param nodes the slot element
* @return <code>true</code> if key is matching
*/
@SuppressWarnings("deprecation")
public static boolean isMatchPreviousAccessKeys(List<Element> nodes) {
if (nodes != null && !nodes.isEmpty()) {
final Slot slot = new EntityFactory<>(Slot.class).fromElement(nodes.get(0));
final Slot cSlot = SlotManager.instance().getSlotById(slot.getSlotId());

final MIRAccessKeyPair accKP = MIRAccessKeyManager.getKeyPair(cSlot.getMCRObjectID());

return accKP != null
&& (accKP.getReadKey().equals(slot.getReadKey()) || accKP.getWriteKey().equals(slot.getWriteKey()));
}
return false;
}

/**
* Checks if given slot location and new number is free.
* <p>
* Called from XEditor via <code>xed:call-java</code> (content/rc/slot-includes.xed).
*
* @param nodes the location element
* @return <code>true</code> if slot number is free
*/
public static boolean isFreeId(List<Element> nodes) {
if (nodes != null && !nodes.isEmpty()) {
final Element xml = nodes.get(0);
final Element location = xml.getChild("location");
final String locId = location != null ? location.getAttributeValue("id") : null;
final String newId = location != null ? location.getAttributeValue("newId") : null;

if (locId != null && newId != null) {
final Slot slot = new EntityFactory<>(Slot.class).fromElement(xml);
final MCRCategoryID locCat = new MCRCategoryDAOImpl()
.getCategory(new MCRCategoryID(Slot.CLASSIF_ROOT_LOCATION, locId), 0).getId();
int id = Integer.parseInt(newId);

return slot.getLocation().equals(locCat) && slot.getId() == id || instance().isFreeId(locCat, id);
}
}
return false;
}

public static boolean isActive(String slotId) {
return Optional.ofNullable(instance().getSlotById(slotId)).map(Slot::isActive).orElse(false);
}
Expand Down
Loading