@Test public void testDecorator() throws IOException, ParserConfigurationException, SAXException, JSONException, TransformerException { URL biblioModsRes = SupplementDecoratorTest.class.getResource("supplement-mods.xml"); Document biblioMods = XMLUtils.parseDocument(biblioModsRes.openStream(), true); URL solrRes = SupplementDecoratorTest.class.getResource("supplement-solr.xml"); Document solr = XMLUtils.parseDocument(solrRes.openStream(), true); SolrMemoizationImpl memoization = new SolrMemoizationImpl(); SolrAccess sa = EasyMock.createMock(SolrAccess.class); FedoraAccess fa = EasyMock.createMock(FedoraAccess.class); EasyMock.expect(fa.getBiblioMods("uuid:0bf8e0f3-9c1a-40ca-a23f-c8a52e9e0359")).andReturn(biblioMods).anyTimes(); EasyMock.expect(sa.getSolrDataDocument("uuid:0bf8e0f3-9c1a-40ca-a23f-c8a52e9e0359")).andReturn(solr).anyTimes(); EasyMock.replay(sa,fa); SupplementDecorator dec = new SupplementDecorator(); dec.memo = memoization; dec.fedoraAccess = fa; memoization.setSolrAccess(sa); JSONObject jsonObject = new JSONObject(); jsonObject.put("pid", "uuid:0bf8e0f3-9c1a-40ca-a23f-c8a52e9e0359"); String key = BiblioModsUtils.BIBLIOMODS_PID_DOCUMENT_KEY + "_" + "uuid:0bf8e0f3-9c1a-40ca-a23f-c8a52e9e0359"; Map<String, Object> runtimeContext = new HashMap<>(); runtimeContext.put(key, biblioMods); dec.decorate(jsonObject, runtimeContext); Assert.assertNotNull(jsonObject.getJSONObject("details")); Assert.assertNotNull(jsonObject.getJSONObject("details").getString("date")); }
@Override public void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext) { try { if (jsonObject.has("pid")) { String pid = jsonObject.getString("pid"); if (!PIDSupport.isComposedPID(pid)) { boolean jsonEnhanced = false; Element doc = this.memo.getRememberedIndexedDoc(pid); if (doc == null) doc = this.memo.askForIndexDocument(pid); if (doc != null) { List<String> array = SOLRUtils.array(doc, "details", String.class); if (!array.isEmpty()) { String[] details = super.details(array.get(0)); JSONObject detailsJSONObject = new JSONObject(); if (details.length > 0) { detailsJSONObject.put("date", ItemResourceUtils.preventAutomaticConversion(details[0])); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } jsonEnhanced = true; } } if (!jsonEnhanced) { Document biblioDoc = BiblioModsUtils.getBiblioModsDocument(pid, context, this.fedoraAccess); Element dateIssued = XMLUtils.findElement(biblioDoc.getDocumentElement(), (element) -> { return (element.getLocalName().equals("dateIssued")); }); JSONObject detailsJSONObject = new JSONObject(); if (dateIssued != null) { detailsJSONObject.put("date", dateIssued.getTextContent()); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } } } } } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } catch (JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } }
SupplementDecorator extends AbstractDetailDecorator { @Override public void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext) { try { if (jsonObject.has("pid")) { String pid = jsonObject.getString("pid"); if (!PIDSupport.isComposedPID(pid)) { boolean jsonEnhanced = false; Element doc = this.memo.getRememberedIndexedDoc(pid); if (doc == null) doc = this.memo.askForIndexDocument(pid); if (doc != null) { List<String> array = SOLRUtils.array(doc, "details", String.class); if (!array.isEmpty()) { String[] details = super.details(array.get(0)); JSONObject detailsJSONObject = new JSONObject(); if (details.length > 0) { detailsJSONObject.put("date", ItemResourceUtils.preventAutomaticConversion(details[0])); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } jsonEnhanced = true; } } if (!jsonEnhanced) { Document biblioDoc = BiblioModsUtils.getBiblioModsDocument(pid, context, this.fedoraAccess); Element dateIssued = XMLUtils.findElement(biblioDoc.getDocumentElement(), (element) -> { return (element.getLocalName().equals("dateIssued")); }); JSONObject detailsJSONObject = new JSONObject(); if (dateIssued != null) { detailsJSONObject.put("date", dateIssued.getTextContent()); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } } } } } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } catch (JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } } }
SupplementDecorator extends AbstractDetailDecorator { @Override public void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext) { try { if (jsonObject.has("pid")) { String pid = jsonObject.getString("pid"); if (!PIDSupport.isComposedPID(pid)) { boolean jsonEnhanced = false; Element doc = this.memo.getRememberedIndexedDoc(pid); if (doc == null) doc = this.memo.askForIndexDocument(pid); if (doc != null) { List<String> array = SOLRUtils.array(doc, "details", String.class); if (!array.isEmpty()) { String[] details = super.details(array.get(0)); JSONObject detailsJSONObject = new JSONObject(); if (details.length > 0) { detailsJSONObject.put("date", ItemResourceUtils.preventAutomaticConversion(details[0])); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } jsonEnhanced = true; } } if (!jsonEnhanced) { Document biblioDoc = BiblioModsUtils.getBiblioModsDocument(pid, context, this.fedoraAccess); Element dateIssued = XMLUtils.findElement(biblioDoc.getDocumentElement(), (element) -> { return (element.getLocalName().equals("dateIssued")); }); JSONObject detailsJSONObject = new JSONObject(); if (dateIssued != null) { detailsJSONObject.put("date", dateIssued.getTextContent()); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } } } } } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } catch (JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } }  }
SupplementDecorator extends AbstractDetailDecorator { @Override public void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext) { try { if (jsonObject.has("pid")) { String pid = jsonObject.getString("pid"); if (!PIDSupport.isComposedPID(pid)) { boolean jsonEnhanced = false; Element doc = this.memo.getRememberedIndexedDoc(pid); if (doc == null) doc = this.memo.askForIndexDocument(pid); if (doc != null) { List<String> array = SOLRUtils.array(doc, "details", String.class); if (!array.isEmpty()) { String[] details = super.details(array.get(0)); JSONObject detailsJSONObject = new JSONObject(); if (details.length > 0) { detailsJSONObject.put("date", ItemResourceUtils.preventAutomaticConversion(details[0])); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } jsonEnhanced = true; } } if (!jsonEnhanced) { Document biblioDoc = BiblioModsUtils.getBiblioModsDocument(pid, context, this.fedoraAccess); Element dateIssued = XMLUtils.findElement(biblioDoc.getDocumentElement(), (element) -> { return (element.getLocalName().equals("dateIssued")); }); JSONObject detailsJSONObject = new JSONObject(); if (dateIssued != null) { detailsJSONObject.put("date", dateIssued.getTextContent()); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } } } } } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } catch (JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } }  @Override String getKey(); @Override void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext); @Override boolean apply(JSONObject jsonObject, String context); }
SupplementDecorator extends AbstractDetailDecorator { @Override public void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext) { try { if (jsonObject.has("pid")) { String pid = jsonObject.getString("pid"); if (!PIDSupport.isComposedPID(pid)) { boolean jsonEnhanced = false; Element doc = this.memo.getRememberedIndexedDoc(pid); if (doc == null) doc = this.memo.askForIndexDocument(pid); if (doc != null) { List<String> array = SOLRUtils.array(doc, "details", String.class); if (!array.isEmpty()) { String[] details = super.details(array.get(0)); JSONObject detailsJSONObject = new JSONObject(); if (details.length > 0) { detailsJSONObject.put("date", ItemResourceUtils.preventAutomaticConversion(details[0])); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } jsonEnhanced = true; } } if (!jsonEnhanced) { Document biblioDoc = BiblioModsUtils.getBiblioModsDocument(pid, context, this.fedoraAccess); Element dateIssued = XMLUtils.findElement(biblioDoc.getDocumentElement(), (element) -> { return (element.getLocalName().equals("dateIssued")); }); JSONObject detailsJSONObject = new JSONObject(); if (dateIssued != null) { detailsJSONObject.put("date", dateIssued.getTextContent()); } boolean moreThanZero = detailsJSONObject.keys().hasNext(); if (moreThanZero) { jsonObject.put("details", detailsJSONObject); } } } } } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } catch (JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new GenericApplicationException(e.getMessage()); } }  @Override String getKey(); @Override void decorate(JSONObject jsonObject, Map<String, Object> runtimeContext); @Override boolean apply(JSONObject jsonObject, String context); static final String DETAILS_PERIODICAL_VOLUME; }