/** * Enrich all meta data records with the (blob) content from repository. * * @param cr ContentRelation * @throws WebserverSystemException Thrown if access to repository (Feodra) failed. */ private static void enrichWithMetadataContent(final ContentRelationCreate cr) { final List<MdRecordCreate> mdRecords = cr.getMetadataRecords(); if (mdRecords != null) { for (final MdRecordCreate mdRecord : mdRecords) { if (mdRecord.getContent() == null) { final Datastream ds = new Datastream( mdRecord.getName(), cr.getObjid(), cr.getProperties().getVersionDate(), mdRecord.getMimeType(), mdRecord.getDatastreamLocation(), mdRecord.getControlGroup()); mdRecord.setContent(new String(ds.getStream(), Charset.forName("UTF-8"))); } } } }
/** * Retrieve the properties of the last version (RELS-EXT) and inject values into * ContentRelationCreate object. * * @param cr ContentRelation object * @throws SystemException Thrown in case of internal failure. * @throws ContentRelationNotFoundException Thrown if resource with provided id could not be found * in Fedora repository. */ private static void setRelsExtValues(final ContentRelationCreate cr) throws SystemException, ContentRelationNotFoundException { // retrieve resource with id from Fedora final Datastream relsExt; try { relsExt = new Datastream(Datastream.RELS_EXT_DATASTREAM, cr.getObjid(), null); } catch (final StreamNotFoundException e) { throw new ContentRelationNotFoundException( "Content Relation with id '" + cr.getObjid() + "' could not be found.", e); } final StaxParser sp = new StaxParser(); final RelsExtReadHandler eve = new RelsExtReadHandler(sp); eve.cleanIdentifier(true); sp.addHandler(eve); try { sp.parse(relsExt.getStream()); } catch (final Exception e) { throw new WebserverSystemException(e); } final List<Triple> triples = eve.getElementValues().getTriples(); // write triple values into ContentRelation object for (final Triple triple : triples) { if (triple.getPredicate().equals(TripleStoreUtility.PROP_FRAMEWORK_BUILD)) { cr.setBuildNumber(triple.getObject()); } // creator -------------- else if (triple.getPredicate().equals(TripleStoreUtility.PROP_CREATED_BY_ID)) { cr.getProperties().setCreatedById(triple.getObject()); } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_CREATED_BY_TITLE)) { cr.getProperties().setCreatedByName(triple.getObject()); } // modifier -------------- else if (triple.getPredicate().equals(TripleStoreUtility.PROP_MODIFIED_BY_ID)) { cr.getProperties().setModifiedById(triple.getObject()); } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_MODIFIED_BY_TITLE)) { cr.getProperties().setModifiedByName(triple.getObject()); } // public-status -------------- else if (triple.getPredicate().equals(TripleStoreUtility.PROP_PUBLIC_STATUS)) { final StatusType st; try { st = StatusType.getStatusType(triple.getObject()); } catch (final InvalidStatusException e) { // shouldn't happen throw new SystemException(e); } cr.getProperties().setStatus(st); } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_PUBLIC_STATUS_COMMENT)) { cr.getProperties().setStatusComment(triple.getObject()); } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_OBJECT_TYPE)) { // this is not the ContentRelation type, this is the type of // resource if (!(Constants.CONTENT_RELATION2_OBJECT_TYPE.equals(triple.getObject()) || (Constants.RDF_NAMESPACE_URI + "Statement").equals(triple.getObject()))) { throw new WebserverSystemException("Resource is not from type ContentRelation."); } } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_CONTENT_RELATION_SUBJECT)) { cr.setSubject(triple.getObject()); } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_CONTENT_RELATION_OBJECT)) { cr.setObject(triple.getObject()); } else if (triple .getPredicate() .equals(TripleStoreUtility.PROP_CONTENT_RELATION_DESCRIPTION)) { cr.getProperties().setDescription(triple.getObject()); } else if (triple.getPredicate().equals(TripleStoreUtility.PROP_CONTENT_RELATION_TYPE)) { try { cr.setType(new URI(triple.getObject())); } catch (final URISyntaxException e) { // shouldn't happen throw new SystemException("Stored value for URI in invalid.", e); } } else if (triple .getPredicate() .equals(TripleStoreUtility.PROP_CONTENT_RELATION_OBJECT_VERSION)) { cr.setObjectVersion(triple.getObject()); } else { // add values for mapping LOGGER.warn("Predicate not mapped " + triple.getPredicate() + " = " + triple.getObject()); } } }