Examples of Datastream


Examples of org.fcrepo.server.storage.types.Datastream

            checkDatastreamID(dsID);
            checkDatastreamLabel(dsLabel);

            w = m_manager.getWriter(Server.USE_DEFINITIVE_STORE, context, pid);
            Datastream ds;
            if (controlGroup.equals("X")) {
                ds = new DatastreamXMLMetadata();
                ds.DSInfoType = ""; // field is now deprecated
                try {
                    InputStream in;
                    MIMETypedStream mimeTypedStream = null;
                    if (dsLocation.startsWith(DatastreamManagedContent.UPLOADED_SCHEME)) {
                        in = getTempStream(dsLocation);
                    } else {
                        ContentManagerParams params = new ContentManagerParams(dsLocation);
                        params.setContext(context);
                        mimeTypedStream = m_contentManager.getExternalContent(params);
                        in = mimeTypedStream.getStream();
                    }
                    // set and validate the content
                    DatastreamXMLMetadata dsm = (DatastreamXMLMetadata) ds;
                    dsm.xmlContent = getEmbeddableXML(in);
                    dsm.DSSize = dsm.xmlContent.length;
                    ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
                                                                 dsID,
                                                                 dsm);
                    if (mimeTypedStream != null) {
                        mimeTypedStream.close();
                    }
                } catch (Exception e) {
                    String extraInfo;
                    if (e.getMessage() == null) {
                        extraInfo = "";
                    } else {
                        extraInfo = " : " + e.getMessage();
                    }
                    throw new GeneralException("Error with " + dsLocation
                                               + extraInfo);
                }
            } else if (controlGroup.equals("M")) {
                ds = new DatastreamManagedContent();
                ds.DSInfoType = "DATA";
                ds.DSLocationType = Datastream.DS_LOCATION_TYPE_URL;
            } else if (controlGroup.equals("R") || controlGroup.equals("E")) {
                ds = new DatastreamReferencedContent();
                ds.DSInfoType = "DATA";
                ds.DSLocationType = Datastream.DS_LOCATION_TYPE_URL;
            } else {
                throw new GeneralException("Invalid control group: "
                                           + controlGroup);
            }
            ds.isNew = true;
            ds.DSControlGrp = controlGroup;
            ds.DSVersionable = versionable;
            if (!dsState.equals("A") && !dsState.equals("D")
                && !dsState.equals("I")) {
                throw new InvalidStateException("The datastream state of \""
                                                + dsState
                                                + "\" is invalid. The allowed values for state are: "
                                                + " A (active), D (deleted), and I (inactive).");
            }
            ds.DSState = dsState;
            // set new datastream id if not provided...
            if (dsID == null || dsID.length() == 0) {
                ds.DatastreamID = w.newDatastreamID();
            } else {
                if (dsID.indexOf(" ") != -1) {
                    throw new GeneralException("Datastream ids cannot contain spaces.");
                }
                if (dsID.indexOf("+") != -1) {
                    throw new GeneralException("Datastream ids cannot contain plusses.");
                }
                if (dsID.indexOf(":") != -1) {
                    throw new GeneralException("Datastream ids cannot contain colons.");
                }
                if (w.GetDatastream(dsID, null) != null) {
                    throw new GeneralException("A datastream already exists with ID: "
                                               + dsID);
                } else {
                    ds.DatastreamID = dsID;
                }
            }
            // add version level attributes and
            // create new ds version id ...
            ds.DSVersionID = ds.DatastreamID + ".0";
            ds.DSLabel = dsLabel;
            ds.DSLocation = dsLocation;
            if (dsLocation != null) {
                ValidationUtility.validateURL(dsLocation, ds.DSControlGrp);
            }
            ds.DSFormatURI = formatURI;
            ds.DatastreamAltIDs = altIDs;
            ds.DSMIME = MIMEType;
            ds.DSChecksumType = Datastream.validateChecksumType(checksumType);

            // M reserved datastream validation (X done above)
            if (controlGroup.equals("M")) {
                ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
                                                             dsID,
                                                             ds);
            }

            if (checksum != null && checksumType != null) {
                String check = ds.getChecksum();
                if (!checksum.equals(check)) {
                    throw new ValidationException("Checksum Mismatch: " + check);
                }
            }
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

            // context, w, datastreamId);
            // }

            // instantiate the right class of datastream
            // (inline xml "X" datastreams have already been rejected)
            Datastream newds;
            if (orig.DSControlGrp.equals("M")) {
                newds = new DatastreamManagedContent();
            } else {
                newds = new DatastreamReferencedContent();
            }
            // update ds attributes that are common to all versions...
            // first, those that cannot be changed by client...
            newds.DatastreamID = orig.DatastreamID;
            newds.DSControlGrp = orig.DSControlGrp;
            newds.DSInfoType = orig.DSInfoType;
            // next, those that can be changed by client...
            newds.DSState = orig.DSState;
            newds.DSVersionable = orig.DSVersionable;

            // update ds version-level attributes, and
            // make sure ds gets a new version id
            newds.DSVersionID = w.newDatastreamID(datastreamId);
            newds.DSLabel = dsLabel;
            newds.DSMIME = mimeType;
            newds.DSFormatURI = formatURI;
            newds.DatastreamAltIDs = altIDs;
            nowUTC = Server.getCurrentDate(context);
            newds.DSCreateDT = nowUTC;
            // newds.DSSize will be computed later
            newds.DSLocation = dsLocation;
            newds.DSLocationType = Datastream.DS_LOCATION_TYPE_URL;
            newds.DSChecksumType = checksumType;

            // validate reserved datastreams (type M and X) unless unchanged:
            if (!newds.DSLocation.startsWith(DatastreamManagedContent.COPY_SCHEME) &&
                !newds.DSLocation.equals(orig.DSLocation)) {
              ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
                                                         datastreamId,
                                                         newds);
            }

            // next, add the datastream via the object writer
            w.addDatastream(newds, orig.DSVersionable);

            // if a checksum is passed in verify that the checksum computed for
            // the datastream
            // matches the one that is passed in.
            if (checksum != null) {
                if (checksumType == null) {
                    newds.DSChecksumType = orig.DSChecksumType;
                }
                String check = newds.getChecksum();
                if (!checksum.equals(check)) {
                    throw new ValidationException("Checksum Mismatch: " + check);
                }
            }
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

                                                   checksumType,
                                                   checksum);

            checkDatastreamLabel(dsLabel);
            w = m_manager.getWriter(Server.USE_DEFINITIVE_STORE, context, pid);
            Datastream orig =
                    w.GetDatastream(datastreamId, null);
            if (orig == null) {
                throw new DatastreamNotFoundException("Object " + pid + " has no datastream "
                                                      + datastreamId + " to modify");
            }

            XMLDatastreamProcessor origxml = new XMLDatastreamProcessor(orig);

            // if provided, check request lastModifiedDate against the datastream,
            // rejecting the request if the datastream's mod date is more recent.
            if (lastModifiedDate != null) {
                if (lastModifiedDate.before(orig.DSCreateDT)) {
                    String dsDate = DateUtility.convertDateToXSDString(w.getLastModDate());
                    String reqDate = DateUtility.convertDateToXSDString(lastModifiedDate);
                    String msg = String.format("%s/%s lastModifiedDate (%s) " +
                                               "is more recent than the " +
                                               "request (%s)", pid,
                                               datastreamId, dsDate, reqDate);
                    throw new DatastreamLockedException(msg);
                }
            }

            // some forbidden scenarios...
            if (orig.DSState.equals("D")) {
                throw new GeneralException("Changing attributes on deleted datastreams is forbidden.");
            }
            if (!orig.DSControlGrp.equals("X") && !orig.DSControlGrp.equals("M")) {
                throw new GeneralException("Only content of inline XML and managed content"
                                           + " datastreams may be modified by value.\n"
                                           + "Use modifyDatastreamByReference instead.");
            }

            // A NULL INPUT PARM MEANS NO CHANGE TO DS ATTRIBUTE...
            // if input parms are null, the ds attribute should not be changed,
            // so set the parm values to the existing values in the datastream.
            if (dsLabel == null) {
                dsLabel = orig.DSLabel;
            }
            if (mimeType == null) {
                mimeType = orig.DSMIME;
            }
            if (formatURI == null) {
                formatURI = orig.DSFormatURI;
            }
            if (altIDs == null) {
                altIDs = orig.DatastreamAltIDs;
            }
            if (checksumType == null) {
                checksumType = orig.DSChecksumType;
            } else {
                checksumType = Datastream.validateChecksumType(checksumType);
            }
            if (dsContent != null && "DC".equals(datastreamId)){
                DCFields audited = new DCFields(dsContent);
                try {
                    dsContent = new ByteArrayInputStream(audited.getAsXML(pid).getBytes("UTF-8"));
                } catch (UnsupportedEncodingException uee) {
                    // safely ignore... we know UTF-8 works
                }
            }

            // create new datastream (version) based on existing one
            XMLDatastreamProcessor newdsxml = origxml.newVersion();
            Datastream newds = newdsxml.getDatastream();
            newdsxml.setDSMDClass(origxml.getDSMDClass());
            if (dsContent == null) {
                // If the dsContent input stream parm is null,
                // that means "do not change the content".
                // Accordingly, here we just make a copy of the old content.
                newdsxml.setXMLContent(origxml.getXMLContent());
            } else {
                // set and validate the content
                newdsxml.setXMLContent(getEmbeddableXML(dsContent));
                ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
                                                             orig.DatastreamID,
                                                             newds);
            }

            // update ds attributes that are common to all versions...
            // first, those that cannot be changed by client...
            newds.DatastreamID = orig.DatastreamID;
            newds.DSControlGrp = orig.DSControlGrp;
            newds.DSInfoType = orig.DSInfoType;
            // next, those that can be changed by client...
            newds.DSState = orig.DSState;
            newds.DSVersionable = orig.DSVersionable;

            // update ds version level attributes, and
            // make sure ds gets a new version id
            newds.DSVersionID = w.newDatastreamID(datastreamId);
            newds.DSLabel = dsLabel;
            newds.DatastreamAltIDs = altIDs;
            newds.DSMIME = mimeType;
            newds.DSFormatURI = formatURI;
            Date nowUTC = Server.getCurrentDate(context);
            newds.DSCreateDT = nowUTC;

            newds.DSChecksumType = checksumType;

            // next, add the datastream via the object writer
            w.addDatastream(newds, orig.DSVersionable);

            // if a checksum is passed in verify that the checksum computed for
            // the datastream
            // matches the one that is passed in.
            if (checksum != null) {
                String check = newds.getChecksum();
                if (!checksum.equals(check)) {
                    throw new ValidationException("Checksum Mismatch: " + check);
                }
            }
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

            logger.debug("Getting Reader");
            r = m_manager.getReader(Server.USE_DEFINITIVE_STORE, context, pid);
            logger.debug("Getting datastream:" + datastreamID + "date: "
                         + versionDate);
            Datastream ds = r.GetDatastream(datastreamID, versionDate);
            logger.debug("Got Datastream, comparing checksum");
            boolean check = ds.compareChecksum();
            logger.debug("compared checksum = " + check);

            return check ? ds.getChecksum() : "Checksum validation error";
        } finally {
            // Logger completion
            if (logger.isInfoEnabled()) {
                StringBuilder logMsg =
                        new StringBuilder("Completed compareDatastreamChecksum(");
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

                w = m_manager.getWriter(false, context, pid);
            } catch (ObjectNotInLowlevelStorageException e ){
                throw new ObjectNotFoundException("Object " + pid + " does not exist.");
            }

            Datastream currentDS = w.GetDatastream(dsID, null);
            if (currentDS == null) {
                    throw new DatastreamNotFoundException("Datastream " + dsID + " not found");
            }

            if (currentDS.DSControlGrp.equals("X")) {

                // take a copy of the existing datastream versions
                Date[] versions = w.getDatastreamVersions(dsID);
                Map<Date, Datastream> copyDS = new HashMap<Date, Datastream>();
                for (Date version: versions) {
                    Datastream d = w.GetDatastream(dsID, version);
                    copyDS.put(version, d.copy());
                }

                // purge the existing datastream (all versions)
                w.removeDatastream(dsID, null, null);
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

     * values is the PID of the object.
     */
    private static void populateDC(Context ctx, DigitalObject obj, DOWriter w,
            Date nowUTC) throws IOException, ServerException {
        logger.debug("Adding/Checking default DC datastream");
        Datastream dc = w.GetDatastream("DC", null);
        DCFields dcf;
        XMLDatastreamProcessor dcxml = null;

        if (dc == null) {
            dcxml = new XMLDatastreamProcessor("DC");
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

                // DATASTREAM STORAGE:
                // copy and store any datastreams of type Managed Content
                Iterator<String> dsIDIter = obj.datastreamIdIterator();
                while (dsIDIter.hasNext()) {
                    String dsID = dsIDIter.next();
                    Datastream dStream =
                            obj.datastreams(dsID).iterator().next();
                    String controlGroupType = dStream.DSControlGrp;
                    // if it's managed, we might need to grab content
                    if (controlGroupType.equalsIgnoreCase("M")) {
                        // iterate over all versions of this dsID
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

        Iterable<Datastream> policyDatastreams = object.datastreams(FedoraPolicyStore.FESL_POLICY_DATASTREAM);

        // try to get the latest policy datastream version
        Date latest = null;
        Datastream policyDatastream = null;
        for (Datastream ds : policyDatastreams) {
            if (latest == null || ds.DSCreateDT.after(latest)) {
                latest = ds.DSCreateDT;
                policyDatastream = ds;
            }
        }
        // null means no policy datastream found
        if (policyDatastream != null ) {
            // add to cache
            System.out.println("   Adding " + object.getPid() + " to index.");
            String policy = new String(IOUtils.toByteArray(policyDatastream.getContentStream()), "UTF-8");
            // TODO: PolicyIndex would benefit from methods that can accept streams
            m_policyIndex.addPolicy(object.getPid(), policy);
        }

View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

            if (state == null) {
                al.add(dsId);
            } else {
                // below should never return null -- already know id exists,
                // and am asking for any the latest existing one.
                Datastream ds = GetDatastream(dsId, null);
                if (ds.DSState.equals(state)) {
                    al.add(dsId);
                }
            }
        }
View Full Code Here

Examples of org.fcrepo.server.storage.types.Datastream

     */
    @Override
    public Datastream GetDatastream(String datastreamID, Date versDateTime) {
        // get the one with the closest creation date
        // without going over
        Datastream result = null;
        long bestTimeDifference = Long.MAX_VALUE;
        long latestCreateTime = -1;
        long vTime = -1;
        if (versDateTime != null) {
            vTime = versDateTime.getTime();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.