@Test public void findPSPPIDsTest() throws MetsExportException { new MockFedoraClient(); new MockSearchView(); MetaModelRepository.setInstance("ndk", "ndkEborn"); RemoteStorage remoteStorage = new RemoteStorage(client); MetsContext ctx = new MetsContext(); ctx.setRemoteStorage(remoteStorage); ctx.setFedoraClient(remoteStorage.getClient()); List<String> pspIDs = MetsUtils.findPSPPIDs("uuid:26342028-12c8-4446-9217-d3c9f249bd13", ctx, true); Set<String> setPspIDs = new HashSet<>(pspIDs); assertTrue("pspIds aren't unique", pspIDs.size() == setPspIDs.size()); List<String> pspIdPeriodical = MetsUtils.findPSPPIDs("uuid:8548cc82-3601-45a6-8eb0-df6538db4de6", ctx, true); assertTrue(pspIdPeriodical.size() > 0); }
public static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren) throws MetsExportException { List<String> result = new ArrayList<>(); DigitalObject dObj; if (ctx.getFedoraClient() != null) { dObj = readFoXML(pid, ctx.getFedoraClient()); } else { dObj = readFoXML(ctx.getPath() + File.separator + pid + ".xml"); } String parentId = pid; String parentModel = null; String parentType = null; List<Element> parentRels = null; DigitalObject parentdbObj = null; String firstParentType = null; while (parentId != null) { if (ctx.getFedoraClient() != null) { parentdbObj = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObj = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } parentRels = FoxmlUtils.findDatastream(parentdbObj, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); parentModel = MetsUtils.getModel(parentRels); parentType = getElementType(parentModel); if ((parentId.equals(pid)) && (firstParentType == null)) { firstParentType = parentType; } String oldParentId = parentId; if (ctx.getFedoraClient() != null) { parentId = MetsUtils.getParent(parentId, ctx.getRemoteStorage()); } else { parentId = MetsUtils.getParent(parentId, ctx.getFsParentMap()); } if (Const.PSPElements.contains(parentType)) { if (Const.SUPPLEMENT.equals(parentType)) { if (parentId != null) { DigitalObject parentdbObjSupp; if (ctx.getFedoraClient() != null) { parentdbObjSupp = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObjSupp = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } List<Element> parentRelsSupp = FoxmlUtils.findDatastream(parentdbObjSupp, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); String parentTypeSupp = getElementType(MetsUtils.getModel(parentRelsSupp)); if (Const.MONOGRAPH_UNIT.equals(parentTypeSupp) || (Const.ISSUE.equals(parentTypeSupp))) { } else { result.add(oldParentId); } } } else { result.add(oldParentId); } } } if (fillChildren) { findChildPSPs(dObj, ctx, result, firstParentType); } return Collections.unmodifiableList(result); }
MetsUtils { public static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren) throws MetsExportException { List<String> result = new ArrayList<>(); DigitalObject dObj; if (ctx.getFedoraClient() != null) { dObj = readFoXML(pid, ctx.getFedoraClient()); } else { dObj = readFoXML(ctx.getPath() + File.separator + pid + ".xml"); } String parentId = pid; String parentModel = null; String parentType = null; List<Element> parentRels = null; DigitalObject parentdbObj = null; String firstParentType = null; while (parentId != null) { if (ctx.getFedoraClient() != null) { parentdbObj = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObj = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } parentRels = FoxmlUtils.findDatastream(parentdbObj, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); parentModel = MetsUtils.getModel(parentRels); parentType = getElementType(parentModel); if ((parentId.equals(pid)) && (firstParentType == null)) { firstParentType = parentType; } String oldParentId = parentId; if (ctx.getFedoraClient() != null) { parentId = MetsUtils.getParent(parentId, ctx.getRemoteStorage()); } else { parentId = MetsUtils.getParent(parentId, ctx.getFsParentMap()); } if (Const.PSPElements.contains(parentType)) { if (Const.SUPPLEMENT.equals(parentType)) { if (parentId != null) { DigitalObject parentdbObjSupp; if (ctx.getFedoraClient() != null) { parentdbObjSupp = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObjSupp = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } List<Element> parentRelsSupp = FoxmlUtils.findDatastream(parentdbObjSupp, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); String parentTypeSupp = getElementType(MetsUtils.getModel(parentRelsSupp)); if (Const.MONOGRAPH_UNIT.equals(parentTypeSupp) || (Const.ISSUE.equals(parentTypeSupp))) { } else { result.add(oldParentId); } } } else { result.add(oldParentId); } } } if (fillChildren) { findChildPSPs(dObj, ctx, result, firstParentType); } return Collections.unmodifiableList(result); } }
MetsUtils { public static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren) throws MetsExportException { List<String> result = new ArrayList<>(); DigitalObject dObj; if (ctx.getFedoraClient() != null) { dObj = readFoXML(pid, ctx.getFedoraClient()); } else { dObj = readFoXML(ctx.getPath() + File.separator + pid + ".xml"); } String parentId = pid; String parentModel = null; String parentType = null; List<Element> parentRels = null; DigitalObject parentdbObj = null; String firstParentType = null; while (parentId != null) { if (ctx.getFedoraClient() != null) { parentdbObj = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObj = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } parentRels = FoxmlUtils.findDatastream(parentdbObj, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); parentModel = MetsUtils.getModel(parentRels); parentType = getElementType(parentModel); if ((parentId.equals(pid)) && (firstParentType == null)) { firstParentType = parentType; } String oldParentId = parentId; if (ctx.getFedoraClient() != null) { parentId = MetsUtils.getParent(parentId, ctx.getRemoteStorage()); } else { parentId = MetsUtils.getParent(parentId, ctx.getFsParentMap()); } if (Const.PSPElements.contains(parentType)) { if (Const.SUPPLEMENT.equals(parentType)) { if (parentId != null) { DigitalObject parentdbObjSupp; if (ctx.getFedoraClient() != null) { parentdbObjSupp = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObjSupp = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } List<Element> parentRelsSupp = FoxmlUtils.findDatastream(parentdbObjSupp, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); String parentTypeSupp = getElementType(MetsUtils.getModel(parentRelsSupp)); if (Const.MONOGRAPH_UNIT.equals(parentTypeSupp) || (Const.ISSUE.equals(parentTypeSupp))) { } else { result.add(oldParentId); } } } else { result.add(oldParentId); } } } if (fillChildren) { findChildPSPs(dObj, ctx, result, firstParentType); } return Collections.unmodifiableList(result); }  }
MetsUtils { public static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren) throws MetsExportException { List<String> result = new ArrayList<>(); DigitalObject dObj; if (ctx.getFedoraClient() != null) { dObj = readFoXML(pid, ctx.getFedoraClient()); } else { dObj = readFoXML(ctx.getPath() + File.separator + pid + ".xml"); } String parentId = pid; String parentModel = null; String parentType = null; List<Element> parentRels = null; DigitalObject parentdbObj = null; String firstParentType = null; while (parentId != null) { if (ctx.getFedoraClient() != null) { parentdbObj = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObj = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } parentRels = FoxmlUtils.findDatastream(parentdbObj, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); parentModel = MetsUtils.getModel(parentRels); parentType = getElementType(parentModel); if ((parentId.equals(pid)) && (firstParentType == null)) { firstParentType = parentType; } String oldParentId = parentId; if (ctx.getFedoraClient() != null) { parentId = MetsUtils.getParent(parentId, ctx.getRemoteStorage()); } else { parentId = MetsUtils.getParent(parentId, ctx.getFsParentMap()); } if (Const.PSPElements.contains(parentType)) { if (Const.SUPPLEMENT.equals(parentType)) { if (parentId != null) { DigitalObject parentdbObjSupp; if (ctx.getFedoraClient() != null) { parentdbObjSupp = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObjSupp = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } List<Element> parentRelsSupp = FoxmlUtils.findDatastream(parentdbObjSupp, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); String parentTypeSupp = getElementType(MetsUtils.getModel(parentRelsSupp)); if (Const.MONOGRAPH_UNIT.equals(parentTypeSupp) || (Const.ISSUE.equals(parentTypeSupp))) { } else { result.add(oldParentId); } } } else { result.add(oldParentId); } } } if (fillChildren) { findChildPSPs(dObj, ctx, result, firstParentType); } return Collections.unmodifiableList(result); }  static XMLGregorianCalendar getCurrentDate(); static Properties getMimeToExtension(); static String getElementType(String  model); static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren); static String getProperty(String name, java.util.List<PropertyType> properties); static List<Element> removeSchemaLocation(List<Element> elements); static List<Element> removeModsCollection(List<Element> elements); static byte[] getBinaryDataStreams(List<DatastreamType> datastreams, String type); static boolean equalDataStreams(String dataStream, String streamName); static Document getDocumentFromList(List<Element> elements); static String xPathEvaluateString(List<Element> elements, String xPath); static Node xPathEvaluateNode(List<Element> elements, String xPath); static String getModel(List<Element> relExtStream); static void copyStream(InputStream is, OutputStream os); static byte[] getBinaryDataStreams(FedoraClient fedoraClient, IMetsElement metsElement, String streamName); static HashMap<String, FileGrp> initFileGroups(); static HashMap<String, FileGrp> initAudioFileGroups(); static HashMap<String, FileGrp> initAudioFileGroups(HashMap<String, FileGrp> fileGrpMap); static DigitalObject readFoXML(String path); static DigitalObject readFoXML(String uuid, FedoraClient client); static List<String> validateAgainstXSD(Document document, InputStream xsd); static List<String> validateAgainstXSD(File file, InputStream xsd); static boolean hasReferenceXML(String name); static String validateIdentifier(String identifier); static String removeNonAlpabetChars(String inputString); static void saveInfoFile(String path, MetsContext metsContext, String md5, String fileMd5Name, File metsFile); static String getPackageID(IMetsElement element); static DigitalObject readRelatedFoXML(String uuid, FedoraClient client); static DigitalObject readRelatedFoXML(String path, String fileName); static FileMD5Info getDigestAndCopy(InputStream is, OutputStream os); static FileMD5Info getDigest(InputStream is); static String getParent(String uuid, RemoteStorage remoteStorage); static String getParent(String uuid, Map<String, String> fileSystemParents); static Document getDocumentFromBytes(byte[] bytes); static void deleteFolder(File folder); static HashMap<String, FileGrp> initEbornFileGroups(); }
MetsUtils { public static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren) throws MetsExportException { List<String> result = new ArrayList<>(); DigitalObject dObj; if (ctx.getFedoraClient() != null) { dObj = readFoXML(pid, ctx.getFedoraClient()); } else { dObj = readFoXML(ctx.getPath() + File.separator + pid + ".xml"); } String parentId = pid; String parentModel = null; String parentType = null; List<Element> parentRels = null; DigitalObject parentdbObj = null; String firstParentType = null; while (parentId != null) { if (ctx.getFedoraClient() != null) { parentdbObj = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObj = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } parentRels = FoxmlUtils.findDatastream(parentdbObj, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); parentModel = MetsUtils.getModel(parentRels); parentType = getElementType(parentModel); if ((parentId.equals(pid)) && (firstParentType == null)) { firstParentType = parentType; } String oldParentId = parentId; if (ctx.getFedoraClient() != null) { parentId = MetsUtils.getParent(parentId, ctx.getRemoteStorage()); } else { parentId = MetsUtils.getParent(parentId, ctx.getFsParentMap()); } if (Const.PSPElements.contains(parentType)) { if (Const.SUPPLEMENT.equals(parentType)) { if (parentId != null) { DigitalObject parentdbObjSupp; if (ctx.getFedoraClient() != null) { parentdbObjSupp = readFoXML(parentId, ctx.getFedoraClient()); } else { parentdbObjSupp = readFoXML(ctx.getPath() + File.separator + parentId + ".xml"); } List<Element> parentRelsSupp = FoxmlUtils.findDatastream(parentdbObjSupp, "RELS-EXT").getDatastreamVersion().get(0).getXmlContent().getAny(); String parentTypeSupp = getElementType(MetsUtils.getModel(parentRelsSupp)); if (Const.MONOGRAPH_UNIT.equals(parentTypeSupp) || (Const.ISSUE.equals(parentTypeSupp))) { } else { result.add(oldParentId); } } } else { result.add(oldParentId); } } } if (fillChildren) { findChildPSPs(dObj, ctx, result, firstParentType); } return Collections.unmodifiableList(result); }  static XMLGregorianCalendar getCurrentDate(); static Properties getMimeToExtension(); static String getElementType(String  model); static List<String> findPSPPIDs(String pid, MetsContext ctx, boolean fillChildren); static String getProperty(String name, java.util.List<PropertyType> properties); static List<Element> removeSchemaLocation(List<Element> elements); static List<Element> removeModsCollection(List<Element> elements); static byte[] getBinaryDataStreams(List<DatastreamType> datastreams, String type); static boolean equalDataStreams(String dataStream, String streamName); static Document getDocumentFromList(List<Element> elements); static String xPathEvaluateString(List<Element> elements, String xPath); static Node xPathEvaluateNode(List<Element> elements, String xPath); static String getModel(List<Element> relExtStream); static void copyStream(InputStream is, OutputStream os); static byte[] getBinaryDataStreams(FedoraClient fedoraClient, IMetsElement metsElement, String streamName); static HashMap<String, FileGrp> initFileGroups(); static HashMap<String, FileGrp> initAudioFileGroups(); static HashMap<String, FileGrp> initAudioFileGroups(HashMap<String, FileGrp> fileGrpMap); static DigitalObject readFoXML(String path); static DigitalObject readFoXML(String uuid, FedoraClient client); static List<String> validateAgainstXSD(Document document, InputStream xsd); static List<String> validateAgainstXSD(File file, InputStream xsd); static boolean hasReferenceXML(String name); static String validateIdentifier(String identifier); static String removeNonAlpabetChars(String inputString); static void saveInfoFile(String path, MetsContext metsContext, String md5, String fileMd5Name, File metsFile); static String getPackageID(IMetsElement element); static DigitalObject readRelatedFoXML(String uuid, FedoraClient client); static DigitalObject readRelatedFoXML(String path, String fileName); static FileMD5Info getDigestAndCopy(InputStream is, OutputStream os); static FileMD5Info getDigest(InputStream is); static String getParent(String uuid, RemoteStorage remoteStorage); static String getParent(String uuid, Map<String, String> fileSystemParents); static Document getDocumentFromBytes(byte[] bytes); static void deleteFolder(File folder); static HashMap<String, FileGrp> initEbornFileGroups();  }