Package org.fcrepo.server.errors

Examples of org.fcrepo.server.errors.GeneralException


                    msg.append("Cannot purge entire datastream because it\n");
                    msg.append("is used by the following disseminators:");
                    for (int i = 0; i < usedList.size(); i++) {
                        msg.append("\n - " + usedList.get(i));
                    }
                    throw new GeneralException(msg.toString());
                }
            }
            // add an explanation of what happened to the user-supplied message.
            if (logMessage == null) {
                logMessage = "";
View Full Code Here


        } catch (Exception e) {
            String message = e.getMessage();
            if (message == null) {
                message = "";
            }
            throw new GeneralException("XML was not well-formed. " + message, e);
        }
    }
View Full Code Here

            try {
                Method method =
                        deploymentClass.getMethod("reflectMethods", (Class[]) null);
                return (MethodDef[]) method.invoke(null, (Object[]) null);
            } catch (Exception e) {
                throw new GeneralException("[DynamicAccessImpl] returned error when "
                        + "attempting to get dynamic method definitions. "
                        + "The underlying error class was: "
                        + e.getClass().getName()
                        + ". The message "
                        + "was \""
View Full Code Here

                }
                Set<RelationshipTuple> tuples =
                        r.getRelationships(subj, pred, null);
                return tuples.toArray(new RelationshipTuple[tuples.size()]);
            } catch (URISyntaxException e) {
                throw new GeneralException("Relationship must be a URI", e);
            }
        } finally {
            // Logger completion
            if (logger.isInfoEnabled()) {
                StringBuilder logMsg =
View Full Code Here

                    .getClass()
                    .getName()
                    .equalsIgnoreCase("org.fcrepo.server.storage.types.MIMETypedStream")) {
                return (MIMETypedStream) result;
            } else {
                throw new GeneralException("[DynamicAccessImpl] returned error. "
                        + "Internal service must return a MIME typed stream. "
                        + "(see org.fcrepo.server.storage.types.MIMETypedStream)");
            }
        } else {
            // FIXIT! (FUTURE) Open up the possibility of there being other
View Full Code Here

            // FIXME: see FCREPO-765 - add proper auth when migrating this to an Admin module, for now use same permissions as reloading policies
            m_authz.enforceReloadPolicies(context);

            if (!controlGroup.equals("M"))
                throw new GeneralException("Invalid target controlGroup " + controlGroup + ".  Only \"M\" is currently supported");

            try {
                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);

                // add back each datastream version in reverse order as managed content
                // (order might not strictly be necessary)
                Arrays.sort(versions);
                for (int i = versions.length - 1; i >= 0; i--) {

                    // get a managed content copy of this datastream version
                    DatastreamXMLMetadata existing = (DatastreamXMLMetadata)copyDS.get(versions[i]);
                    DatastreamManagedContent newDS = new DatastreamManagedContent();
                    existing.copy(newDS);

                    // X control group will have been copied over by above, reset it
                    newDS.DSControlGrp = controlGroup;

                    // probably not necessary, but just in case...
                    newDS.DSLocation = null;
                    newDS.DSLocationType = null;

                    // add character encoding to mime type (will always be UTF-8 as it has come from X datastream in FOXML)
                    if (setMIMETypeCharset) {
                        if (newDS.DSMIME != null && !newDS.DSMIME.equals("") & !newDS.DSMIME.contains("charset=")) {
                            newDS.DSMIME = newDS.DSMIME + "; charset=UTF-8";
                        } else {
                            newDS.DSMIME = "text/xml; charset=UTF-8";
                        }
                    }

                    byte[] byteContent;

                    // Note: use getContentStream() rather than getting bytes directly, as this is how
                    // X datastreams are disseminated (we want the M content to be identical on
                    // dissemination)
                    if (reformat) {
                        byteContent = this.getXML(existing.getContentStream(), addXMLHeader);
                    } else {
                        // add just the XML header declaring encoding, if requested
                        if (addXMLHeader) {
                            byte[] header;
                            try {
                                header = xmlHeader.getBytes("UTF-8");
                            } catch (UnsupportedEncodingException e) {
                                // should never happen
                                throw new RuntimeException(e);
                            }
                            byte[] existingContent;
                            try {
                                existingContent = IOUtils.toByteArray(existing.getContentStream());
                            } catch (IOException e) {
                                throw new GeneralException("Error reading existing content from X datastream", e);
                            }
                            byteContent = Arrays.copyOf(header, header.length + existingContent.length);
                            System.arraycopy(existing.xmlContent, 0, byteContent, header.length, existingContent.length);
                        } else {
                            try {
                                byteContent = IOUtils.toByteArray(existing.getContentStream());
                            } catch (IOException e) {
                                throw new GeneralException("Error reading existing content from X datastream", e);
                            }
                        }
                    }

                    // add the content stream
                    MIMETypedStream content = new MIMETypedStream(null, new ByteArrayInputStream(byteContent), null, byteContent.length);
                    newDS.putContentStream(content);

                    // checksum only needs recalc if we added a header
                    // note getChecksum() caters for checksum type set to disabled
                    if (addXMLHeader) {
                        logger.debug("Recalculating checksum.  Type=" + newDS.DSChecksumType + " Existing checksum: " + newDS.DSChecksum != null ? newDS.DSChecksum : "none");

                        // forces computation rather than return existing
                        newDS.DSChecksum = Datastream.CHECKSUM_NONE;
                        newDS.DSChecksum = newDS.getChecksum();

                        logger.debug("New checksum: " + newDS.DSChecksum);
                        logger.debug("Testing new checksum, response is {}", newDS.compareChecksum());
                    }

                    w.addDatastream(newDS, true);
                }

                Date nowUTC = Server.getCurrentDate(context);
                String logMessage = "Modified datastream control group for " + pid + " " + dsID + " from " + currentDS.DSControlGrp + " to " + controlGroup;
                addAuditRecord(context,
                               w,
                               "modifyDatastreamControlGroup",
                               dsID,
                               logMessage,
                               nowUTC);

                w.commit(logMessage);
                return versions;

            } else { // existing control group is not X
                if (currentDS.DSControlGrp.equals("M")) {
                    // nothing modified
                    return new Date[0];
                } else {
                    throw new GeneralException("Original control group must be X, it is " + currentDS.DSControlGrp);
                }
            }

        } finally {
            // Logger completion
View Full Code Here

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

                                .getObjectProfile(reposBaseURL,
                                                  profile,
                                                  asOfDateTime)
                                .getBytes("UTF-8"));
            } catch (UnsupportedEncodingException uee) {
                throw new GeneralException("[DefaultDisseminatorImpl] An error has occurred. "
                        + "The error was a \""
                        + uee.getClass().getName()
                        + "\"  . The "
                        + "Reason was \""
                        + uee.getMessage()
View Full Code Here

                            .getMethodIndex(reposBaseURL,
                                            reader.GetObjectPID(),
                                            methods,
                                            asOfDateTime).getBytes("UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            throw new GeneralException("[DefaultDisseminatorImpl] An error has occurred. "
                    + "The error was a \""
                    + uee.getClass().getName()
                    + "\"  . The "
                    + "Reason was \""
                    + uee.getMessage()
View Full Code Here

                                          context
                                                  .getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME),
                                          reader,
                                          asOfDateTime).getBytes("UTF-8"));
        } catch (Exception e) {
            throw new GeneralException("[DefaultDisseminatorImpl] An error has occurred. "
                    + "The error was a \""
                    + e.getClass().getName()
                    + "\"  . The " + "Reason was \"" + e.getMessage() + "\"  .");
        }
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.