Package org.fcrepo.server.errors

Examples of org.fcrepo.server.errors.GeneralException


        try {
            // in case the policy doesn't exist (corrupt policy index, failed to add because invalid, etc)
            m_policyIndex.deletePolicy(pid);
        } catch (PolicyIndexException e) {
            throw new GeneralException("Error deleting policy " + pid + " from policy index: " + e.getMessage(), e);
        }
    }
View Full Code Here


                                          new StreamResult(out));
                }
                out.flush();

            } else {
                throw new GeneralException("No object profile returned");
            }
        } catch (ServerException e) {
            throw e;
        } catch (Throwable th) {
            String message = "Error getting object profile";
            logger.error(message, th);
            throw new GeneralException(message, th);
        } finally {
            try {
                if (pr != null) {
                    pr.close();
                }
View Full Code Here

                logger.error(message);
            }
        } catch (ServerException e) {
            throw e;
        } catch (Throwable th) {
            throw new GeneralException("Error while getting next PID", th);
        } finally {
            try {
                if (pr != null) {
                    pr.close();
                }
View Full Code Here

        } catch (ServerException e) {
            throw e;
        } catch (Throwable th) {
            String message = "Error listing methods";
            logger.error(message, th);
            throw new GeneralException(message, th);
        } finally {
            try {
                if (pr != null) {
                    pr.close();
                }
View Full Code Here

              + uee.getClass().getName()
              + "\"  . The Reason was \""
              + uee.getMessage()
              + "\"  . String value: " + replaceString + "  . ";
          logger.error(message);
          throw new GeneralException(message);
        }
        logger.debug("Replaced dissURL: " + dissURL.toString()
            + " DissBindingInfo index: " + i);
      }

      DeploymentDSBindSpec dsBindSpec = bmReader
          .getServiceDSInputSpec(null);
      DeploymentDSBindRule rules[] = dsBindSpec.dsBindRules;
      for (DeploymentDSBindRule element : rules) {
        String rulePattern = "(" + element.bindingKeyName + ")";
        if (dissURL.indexOf(rulePattern) != -1) {
          throw new DisseminationException(null, "Data Object " + PID
              + " missing required datastream: "
              + element.bindingKeyName, null, null, null);
        }
      }

      // Substitute method parameter values in dissemination URL
      Enumeration<String> e = h_userParms.keys();
      while (e.hasMoreElements()) {
        String name = null;
        String value = null;
        try {
          name = URLEncoder.encode(e.nextElement(), "UTF-8");
          value = URLEncoder.encode(h_userParms.get(name), "UTF-8");
        } catch (UnsupportedEncodingException uee) {
          String message = "[DisseminationService] An error occured. The error "
              + "was \""
              + uee.getClass().getName()
              + "\"  . The Reason was \""
              + uee.getMessage()
              + "\"  . Parameter name: "
              + name
              + "  . "
              + "Parameter value: " + value + "  .";
          logger.error(message);
          throw new GeneralException(message);
        }
        String pattern = "\\(" + name + "\\)";
        dissURL = substituteString(dissURL, pattern, value);
        logger.debug("User parm substituted in URL: " + dissURL);
      }

      // FIXME Need a more elegant means of handling optional
      // userInputParm
      // method parameters that are not supplied by the invoking client;
      // for now, any optional parms that were not supplied are removed
      // from
      // the outgoing URL. This works because parms are validated in
      // DefaultAccess to insure all required parms are present and all
      // parm
      // names match parm names defined for the specific method. The only
      // unsubstituted parms left in the operationLocation string at this
      // point
      // are those for optional parameters that the client omitted in the
      // initial request so they can safely be removed from the outgoing
      // dissemination URL. This step is only needed when optional
      // parameters
      // are not supplied by the client.
      if (dissURL.indexOf("(") != -1) {
        dissURL = stripParms(dissURL);
        logger.debug("Non-supplied optional userInputParm values removed "
            + "from URL: " + dissURL);
      }

      if (dissURL.indexOf("(") != -1) {
        String datastreamName = dissURL.substring(
            dissURL.indexOf("(") + 1, dissURL.indexOf(")"));
        throw new DisseminationException(null, "Data Object " + PID
            + " missing required datastream: " + datastreamName,
            null, null, null);
      }

      // Resolve content referenced by dissemination result.
      logger.debug("ProtocolType: " + protocolType);
      if (protocolType.equalsIgnoreCase("http")) {

        if (isRedirect) {
          // The dsControlGroupType of Redirect("R") is a special
          // control type
          // used primarily for streaming media. Datastreams of this
          // type are
          // not mediated (proxied by Fedora) and their physical
          // dsLocation is
          // simply redirected back to the client. Therefore, the
          // contents
          // of the MIMETypedStream returned for dissemination
          // requests will
          // contain the raw URL of the dsLocation and will be
          // assigned a
          // special fedora-specific MIME type to identify the stream
          // as
          // a MIMETypedStream whose contents contain a URL to which
          // the client
          // should be redirected.

          InputStream is = null;
          try {
            is = new ByteArrayInputStream(dissURL.getBytes("UTF-8"));
          } catch (UnsupportedEncodingException uee) {
            String message = "[DisseminationService] An error has occurred. "
                + "The error was a \""
                + uee.getClass().getName()
                + "\"  . The "
                + "Reason was \""
                + uee.getMessage()
                + "\"  . String value: " + dissURL + "  . ";
            logger.error(message);
            throw new GeneralException(message);
          }
          logger.debug("Finished assembling dissemination");
          dissemination = new MIMETypedStream(
              "application/fedora-redirect", is, null);
        } else {
View Full Code Here

      String message = "[DisseminationService] An error has occurred. "
          + "The internal dsLocation: \"" + internalDSLocation
          + "\" is " + "not in the required format of: "
          + "\"doPID+DSID+DSVERSIONID\" .";
      logger.error(message);
      throw new GeneralException(message);
    }
    logger.debug("********** Resolving Internal Datastream dsLocation: "
        + dsLocation);
    return dsLocation;
  }
View Full Code Here

            }
        }

        if (dsID != null
            && (dsID.equals("AUDIT") || dsID.equals("FEDORA-AUDITTRAIL"))) {
            throw new GeneralException("Creation of a datastream with an"
                                       + " identifier of 'AUDIT' or 'FEDORA-AUDITTRAIL' is not permitted.");
        }
        DOWriter w = null;
        try {
            m_authz.enforceAddDatastream(context,
                                         pid,
                                         dsID,
                                         altIDs,
                                         MIMEType,
                                         formatURI,
                                         dsLocation,
                                         controlGroup,
                                         dsState,
                                         checksumType,
                                         checksum);

            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;
                }
            }
View Full Code Here

        } catch (AuthzException ae) {
            throw ae;
        } catch (Throwable th) {
            String msg = "Error describing repository";
            logger.error(msg, th);
            throw new GeneralException(msg, th);
        }
    }
View Full Code Here

            }
        }

        if (datastreamId.equals("AUDIT")
            || datastreamId.equals("FEDORA-AUDITTRAIL")) {
            throw new GeneralException("Modification of the system-controlled AUDIT"
                                       + " datastream is not permitted.");
        }

        DOWriter w = null;
        try {
            logger.debug("Entered modifyDatastreamByReference");
            m_authz
                    .enforceModifyDatastreamByReference(context,
                                                        pid,
                                                        datastreamId,
                                                        altIDs,
                                                        mimeType,
                                                        formatURI,
                                                        dsLocation,
                                                        checksumType,
                                                        checksum);

            checkDatastreamLabel(dsLabel);
            w = m_manager.getWriter(Server.USE_DEFINITIVE_STORE, context, pid);
            org.fcrepo.server.storage.types.Datastream orig =
                    w.GetDatastream(datastreamId, null);
            if (orig == null) {
                throw new DatastreamNotFoundException("Object " + pid + " has no datastream "
                                                      + datastreamId + " to modify");
            }
            // 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);
                }
            }

            Date nowUTC; // variable for ds modified date

            // some forbidden scenarios...
            if (orig.DSControlGrp.equals("X")) {
                throw new GeneralException("Inline XML datastreams must be modified by value, not by reference.");
            }
            if (orig.DSState.equals("D")) {
                throw new GeneralException("Changing attributes on deleted datastreams is forbidden.");
            }

            // 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.
View Full Code Here

            }
        }

        if (datastreamId.equals("AUDIT")
            || datastreamId.equals("FEDORA-AUDITTRAIL")) {
            throw new GeneralException("Modification of the system-controlled AUDIT"
                                       + " datastream is not permitted.");
        }
        DOWriter w = null;
        try {
            logger.debug("Entered modifyDatastreamByValue");
            m_authz.enforceModifyDatastreamByValue(context,
                                                   pid,
                                                   datastreamId,
                                                   altIDs,
                                                   mimeType,
                                                   formatURI,
                                                   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...
View Full Code Here

TOP

Related Classes of org.fcrepo.server.errors.GeneralException

Copyright © 2018 www.massapicom. 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.