@Test public void testEhanceByCollection3() throws JSONException, IOException, NoSuchMethodException, IllegalAccessException, CollectionException { ObjectPidsPath p = new ObjectPidsPath(); CollectionsManager colGet = EasyMock.createMock(CollectionsManager.class); FedoraAccess fa = EasyMock.createMock(FedoraAccess.class); replay( colGet, fa); ObjectPidsPath cols = p.injectCollections(colGet); Assert.assertTrue(cols.isEmptyPath()); }
public ObjectPidsPath injectCollections(CollectionsManager col) throws CollectionException { try { if (this.isEmptyPath()) return this; for (String pid : pathFromRootToLeaf) { if (CollectionPidUtils.isCollectionPid(pid)) { return this; } } String[] pathFromRoot = this.getPathFromRootToLeaf(); Set<String> processingCollection = new HashSet<String>(); Map<String,List<String>> m = new HashMap<String, List<String>>(); for (String pid : pathFromRoot) { if (SpecialObjects.REPOSITORY.getPid().equals(pid)) continue; PIDParser parser = new PIDParser(pid); parser.objectPid(); if (parser.isDatastreamPid() || parser.isPagePid()) continue; JSONObject itemJSON = getItemJSON(pid); if (itemJSON.has("collections")) { JSONArray collectionsArray = itemJSON.getJSONArray("collections"); for (int i = 0,ll=collectionsArray.length(); i < ll; i++) { String val = collectionsArray.getString(i); if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } if (!processingCollection.contains(val)) { m.get(pid).add(val); processingCollection.add(val); } } } else { if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } } } List<String> newVals = new ArrayList<String>(); for (String p : pathFromRoot) { List<String> list = m.get(p); if (list != null) { for (String vc : list) { newVals.add(vc); } } newVals.add(p); } return new ObjectPidsPath(newVals); } catch (LexerException e) { throw new CollectionException(e); } }
ObjectPidsPath extends AbstractObjectPath { public ObjectPidsPath injectCollections(CollectionsManager col) throws CollectionException { try { if (this.isEmptyPath()) return this; for (String pid : pathFromRootToLeaf) { if (CollectionPidUtils.isCollectionPid(pid)) { return this; } } String[] pathFromRoot = this.getPathFromRootToLeaf(); Set<String> processingCollection = new HashSet<String>(); Map<String,List<String>> m = new HashMap<String, List<String>>(); for (String pid : pathFromRoot) { if (SpecialObjects.REPOSITORY.getPid().equals(pid)) continue; PIDParser parser = new PIDParser(pid); parser.objectPid(); if (parser.isDatastreamPid() || parser.isPagePid()) continue; JSONObject itemJSON = getItemJSON(pid); if (itemJSON.has("collections")) { JSONArray collectionsArray = itemJSON.getJSONArray("collections"); for (int i = 0,ll=collectionsArray.length(); i < ll; i++) { String val = collectionsArray.getString(i); if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } if (!processingCollection.contains(val)) { m.get(pid).add(val); processingCollection.add(val); } } } else { if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } } } List<String> newVals = new ArrayList<String>(); for (String p : pathFromRoot) { List<String> list = m.get(p); if (list != null) { for (String vc : list) { newVals.add(vc); } } newVals.add(p); } return new ObjectPidsPath(newVals); } catch (LexerException e) { throw new CollectionException(e); } } }
ObjectPidsPath extends AbstractObjectPath { public ObjectPidsPath injectCollections(CollectionsManager col) throws CollectionException { try { if (this.isEmptyPath()) return this; for (String pid : pathFromRootToLeaf) { if (CollectionPidUtils.isCollectionPid(pid)) { return this; } } String[] pathFromRoot = this.getPathFromRootToLeaf(); Set<String> processingCollection = new HashSet<String>(); Map<String,List<String>> m = new HashMap<String, List<String>>(); for (String pid : pathFromRoot) { if (SpecialObjects.REPOSITORY.getPid().equals(pid)) continue; PIDParser parser = new PIDParser(pid); parser.objectPid(); if (parser.isDatastreamPid() || parser.isPagePid()) continue; JSONObject itemJSON = getItemJSON(pid); if (itemJSON.has("collections")) { JSONArray collectionsArray = itemJSON.getJSONArray("collections"); for (int i = 0,ll=collectionsArray.length(); i < ll; i++) { String val = collectionsArray.getString(i); if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } if (!processingCollection.contains(val)) { m.get(pid).add(val); processingCollection.add(val); } } } else { if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } } } List<String> newVals = new ArrayList<String>(); for (String p : pathFromRoot) { List<String> list = m.get(p); if (list != null) { for (String vc : list) { newVals.add(vc); } } newVals.add(p); } return new ObjectPidsPath(newVals); } catch (LexerException e) { throw new CollectionException(e); } } ObjectPidsPath(String... pathFromRootToLeaf);  ObjectPidsPath(List<String> pathFromRootToLeaf); }
ObjectPidsPath extends AbstractObjectPath { public ObjectPidsPath injectCollections(CollectionsManager col) throws CollectionException { try { if (this.isEmptyPath()) return this; for (String pid : pathFromRootToLeaf) { if (CollectionPidUtils.isCollectionPid(pid)) { return this; } } String[] pathFromRoot = this.getPathFromRootToLeaf(); Set<String> processingCollection = new HashSet<String>(); Map<String,List<String>> m = new HashMap<String, List<String>>(); for (String pid : pathFromRoot) { if (SpecialObjects.REPOSITORY.getPid().equals(pid)) continue; PIDParser parser = new PIDParser(pid); parser.objectPid(); if (parser.isDatastreamPid() || parser.isPagePid()) continue; JSONObject itemJSON = getItemJSON(pid); if (itemJSON.has("collections")) { JSONArray collectionsArray = itemJSON.getJSONArray("collections"); for (int i = 0,ll=collectionsArray.length(); i < ll; i++) { String val = collectionsArray.getString(i); if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } if (!processingCollection.contains(val)) { m.get(pid).add(val); processingCollection.add(val); } } } else { if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } } } List<String> newVals = new ArrayList<String>(); for (String p : pathFromRoot) { List<String> list = m.get(p); if (list != null) { for (String vc : list) { newVals.add(vc); } } newVals.add(p); } return new ObjectPidsPath(newVals); } catch (LexerException e) { throw new CollectionException(e); } } ObjectPidsPath(String... pathFromRootToLeaf);  ObjectPidsPath(List<String> pathFromRootToLeaf); @Override ObjectPidsPath cutHead(int indexFrom); @Override ObjectPidsPath cutTail(int indexFrom); @Override ObjectPidsPath injectRepository(); ObjectPidsPath injectCollections(CollectionsManager col); @Override ObjectPidsPath replace(String src, String dest); @Override ObjectPidsPath injectObjectBetween(String injectingObject, Between between); }
ObjectPidsPath extends AbstractObjectPath { public ObjectPidsPath injectCollections(CollectionsManager col) throws CollectionException { try { if (this.isEmptyPath()) return this; for (String pid : pathFromRootToLeaf) { if (CollectionPidUtils.isCollectionPid(pid)) { return this; } } String[] pathFromRoot = this.getPathFromRootToLeaf(); Set<String> processingCollection = new HashSet<String>(); Map<String,List<String>> m = new HashMap<String, List<String>>(); for (String pid : pathFromRoot) { if (SpecialObjects.REPOSITORY.getPid().equals(pid)) continue; PIDParser parser = new PIDParser(pid); parser.objectPid(); if (parser.isDatastreamPid() || parser.isPagePid()) continue; JSONObject itemJSON = getItemJSON(pid); if (itemJSON.has("collections")) { JSONArray collectionsArray = itemJSON.getJSONArray("collections"); for (int i = 0,ll=collectionsArray.length(); i < ll; i++) { String val = collectionsArray.getString(i); if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } if (!processingCollection.contains(val)) { m.get(pid).add(val); processingCollection.add(val); } } } else { if (!m.containsKey(pid)) { m.put(pid, new ArrayList<String>()); } } } List<String> newVals = new ArrayList<String>(); for (String p : pathFromRoot) { List<String> list = m.get(p); if (list != null) { for (String vc : list) { newVals.add(vc); } } newVals.add(p); } return new ObjectPidsPath(newVals); } catch (LexerException e) { throw new CollectionException(e); } } ObjectPidsPath(String... pathFromRootToLeaf);  ObjectPidsPath(List<String> pathFromRootToLeaf); @Override ObjectPidsPath cutHead(int indexFrom); @Override ObjectPidsPath cutTail(int indexFrom); @Override ObjectPidsPath injectRepository(); ObjectPidsPath injectCollections(CollectionsManager col); @Override ObjectPidsPath replace(String src, String dest); @Override ObjectPidsPath injectObjectBetween(String injectingObject, Between between); static final Logger LOGGER; static ObjectPidsPath REPOSITORY_PATH; }