public static void collectResourcesSO(Model m, Collection target) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); if (!(st.object() instanceof Literal) && !(st.object() instanceof Statement)) target.add(st.object()); target.add(st.subject()); } }
public static void replaceResources(Collection src, Collection dest, NodeFactory f, Map o2n) throws ModelException { Iterator it = src.iterator(); while (it.hasNext()) { Statement st = (Statement) it.next(); dest.add(replaceResources(st, f, o2n)); } }
public static void collectPredicates(Model m, Collection target) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); target.add(st.predicate()); } }
private static void addStrings(SolrInputDocument doc, Collection<String> set, SolrName field) { if (set == null || set.size() == 0) { return; } for (String s : set) { add(doc, field, s); } }
// metadata refs use DcsFile ids to reference DcsFile content //But why is this not getting // indexed or is it? private static void addMetadataRefSet( SolrInputDocument doc, Collection<DcsMetadataRef> set, SolrName field, ArchiveStore store) throws IOException { if (set == null || set.size() == 0) { return; } addRefSet(doc, set, field); }
private static void addFixitySet(SolrInputDocument doc, Collection<DcsFixity> set) { if (set == null || set.size() == 0) { return; } for (DcsFixity fix : set) { setadd(doc, FixityField.ALGORITHM, fix.getAlgorithm()); setadd(doc, FixityField.VALUE, fix.getValue()); } }
private static void addRefSet( SolrInputDocument doc, Collection<? extends DcsEntityReference> set, SolrName field) { if (set == null || set.size() == 0) { return; } for (DcsEntityReference ref : set) { setadd(doc, field, ref.getRef()); } }
private static void addCreatorSet(SolrInputDocument doc, Collection<SeadPerson> set) { if (set == null || set.size() == 0) { return; } for (SeadPerson creator : set) { setadd(doc, SeadSolrField.CreatorField.CREATORID, creator.getId()); setadd(doc, SeadSolrField.CreatorField.CREATORIDTYPE, creator.getIdType()); setadd(doc, SeadSolrField.CreatorField.NAME, creator.getName()); } }
private static void addResourceIdentifierSet( SolrInputDocument doc, Collection<DcsResourceIdentifier> set) { if (set == null || set.size() == 0) { return; } for (DcsResourceIdentifier id : set) { setadd(doc, ResourceIdentifierField.AUTHORITY, id.getAuthorityId()); setadd(doc, ResourceIdentifierField.TYPE, id.getTypeId()); setadd(doc, ResourceIdentifierField.VALUE, id.getIdValue()); } }
private static void addFormatSet(SolrInputDocument doc, Collection<DcsFormat> set) { if (set == null || set.size() == 0) { return; } for (DcsFormat fmt : set) { setadd(doc, FormatField.NAME, fmt.getName()); setadd(doc, FormatField.FORMAT, fmt.getFormat()); setadd(doc, FormatField.SCHEMA, fmt.getSchemeUri()); setadd(doc, FormatField.VERSION, fmt.getVersion()); } }
// refactored this out from the three addAction methods above private void addAction(Object actionsCollectionOrMap, ActionDescriptor descriptor) { if (getAction(descriptor.getId()) != null) { throw new IllegalArgumentException( "action with id " + descriptor.getId() + " already exists for this step."); } if (actionsCollectionOrMap instanceof Map) { ((Map) actionsCollectionOrMap).put(new Integer(descriptor.getId()), descriptor); } else { ((Collection) actionsCollectionOrMap).add(descriptor); } }
private static void addManifestationFileSet( SolrInputDocument doc, Collection<DcsManifestationFile> set, ArchiveStore store) throws IOException { for (DcsManifestationFile mf : set) { final String fileRef = mf.getRef() == null ? null : mf.getRef().getRef(); setadd(doc, ManifestationFileField.FILE_REF, fileRef); setadd(doc, ManifestationFileField.PATH, mf.getPath()); final Collection<DcsRelation> rels = mf.getRelSet(); if (rels != null && !rels.isEmpty() && fileRef != null) { addRelationSet(doc, rels); for (DcsRelation rel : rels) { // <doc // field="mf_rel_urn:dataconservancy.org:file/4326762_hasRelationship">urn:dataconservancy.org:rel/isMetadataFor</doc> setadd( doc, ManifestationFileField.DYNAMIC_MF_REL_PREFIX.solrName() + fileRef + "_" + RelationField.RELATION.solrName(), rel.getRelUri()); // <doc // field="mf_rel_urn:dataconservancy.org:file/4326762_relatedTo">http://dataconservancy.org/dcs/entity/article_du</doc> setadd( doc, ManifestationFileField.DYNAMIC_MF_REL_PREFIX.solrName() + fileRef + "_" + RelationField.TARGET.solrName(), rel.getRef().getRef()); } } } }
private static String[] setgetAll(SolrDocument doc, String solrField) { Collection<Object> value_col = doc.getFieldValues(solrField); Collection<Object> isnull_col = doc.getFieldValues(solrField + IS_NULL_FIELD_SUFFIX); if (value_col == null || isnull_col == null) { // System.out.println("returing empty " + field.solrName()); // System.out.println("valuecol " + (value_col == null)); // System.out.println("isnull " + (isnull_col == null)); return new String[] {}; } Boolean[] isnull = isnull_col.toArray(new Boolean[] {}); String[] values = value_col.toArray(new String[] {}); for (int i = 0; i < values.length; i++) { if (isnull[i]) { values[i] = null; } } return values; }
private static void addRelationSet(SolrInputDocument doc, Collection<DcsRelation> set) { if (set == null || set.size() == 0) { return; } for (DcsRelation rel : set) { setadd(doc, RelationField.TARGET, rel.getRef() == null ? null : rel.getRef().getRef()); setadd(doc, RelationField.RELATION, rel.getRelUri()); if (rel.getRef() != null && rel.getRelUri() != null) { doc.addField(RELATION_FIELD_PREFIX + rel.getRelUri(), rel.getRef()); } } }
// returns list of statements protected static void replaceMultSPO( Statement st, NodeFactory f, Map o2n, Collection result, RDFNode toReplace, int position) throws ModelException { Collection replacements; if (toReplace instanceof Statement) { List l = new ArrayList(); replaceMult((Statement) toReplace, f, o2n, l); if (l.size() == 1 && toReplace == l.get(0)) { result.add(st); return; // keep the same } else replacements = l; } else { Object ro = o2n.get(toReplace); if (ro instanceof Collection) replacements = (Collection) ro; else if (ro != null) { replacements = new ArrayList(); replacements.add(ro); } else { // no replacement needed result.add(st); // keep the same statement return; } } for (Iterator it = replacements.iterator(); it.hasNext(); ) { Statement rs = null; Object rr = it.next(); switch (position) { case 0: rs = f.createStatement((Resource) rr, st.predicate(), st.object()); break; case 1: rs = f.createStatement(st.subject(), (Resource) rr, st.object()); break; case 2: rs = f.createStatement(st.subject(), st.predicate(), (RDFNode) rr); break; } result.add(rs); } }
private static void addMetadataSet(SolrInputDocument doc, Collection<DcsMetadata> set) throws IOException { if (set == null || set.size() == 0) { return; } for (DcsMetadata md : set) { setadd(doc, MetadataField.SCHEMA, md.getSchemaUri()); setadd(doc, MetadataField.TEXT, md.getMetadata()); if (md.getMetadata() == null) { continue; } try { Reader in = new StringReader(md.getMetadata()); addXml(doc, "ext_", MetadataField.SEARCH_TEXT.solrName(), new InputSource(in)); in.close(); // Index FGDC String metadata = md.getMetadata(); if (metadata.contains("<metadata>")) // fgdc - change the check { FgdcMapping mapping = new FgdcMapping(); Map<Enum, String> fgdcElements = mapping.map(metadata); Iterator it = fgdcElements.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); add(doc, (SeadSolrField.FgdcField) pair.getKey(), pair.getValue()); it.remove(); // avoids a ConcurrentModificationException } } in.close(); } catch (SAXException e) { throw new IOException(e); } } }
public static void collectNamespaces(Resource r, Collection target) throws ModelException { String ns = r.getNamespace(); if (ns != null) target.add(ns); }
public void addPackageClass(PackageClass pClass) { Document doc; try { doc = getDocument(); } catch (Exception e) { e.printStackTrace(); return; } String name = pClass.getName(); // check if such class exists and remove duplicates Element rootEl = doc.getDocumentElement(); NodeList classEls = rootEl.getElementsByTagName(EL_CLASS); for (int i = 0; i < classEls.getLength(); i++) { Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME); if (name.equals(nameEl.getTextContent())) { rootEl.removeChild(classEls.item(i)); } } Element classNode = doc.createElement(EL_CLASS); doc.getDocumentElement().appendChild(classNode); classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName()); classNode.setAttribute(ATR_STATIC, "false"); Element className = doc.createElement(EL_NAME); className.setTextContent(name); classNode.appendChild(className); Element desrc = doc.createElement(EL_DESCRIPTION); desrc.setTextContent(pClass.getDescription()); classNode.appendChild(desrc); Element icon = doc.createElement(EL_ICON); icon.setTextContent(pClass.getIcon()); classNode.appendChild(icon); // graphics classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics())); // ports List<Port> ports = pClass.getPorts(); if (!ports.isEmpty()) { Element portsEl = doc.createElement(EL_PORTS); classNode.appendChild(portsEl); for (Port port : ports) { portsEl.appendChild(generatePortNode(doc, port)); } } // fields Collection<ClassField> fields = pClass.getFields(); if (!fields.isEmpty()) { Element fieldsEl = doc.createElement(EL_FIELDS); classNode.appendChild(fieldsEl); for (ClassField cf : fields) { fieldsEl.appendChild(generateFieldNode(doc, cf)); } } // write try { writeDocument(doc, new FileOutputStream(xmlFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } }