Search in sources :

Example 6 with DepositReceipt

use of org.swordapp.server.DepositReceipt in project dataverse by IQSS.

the class ContainerManagerImpl method useHeaders.

@Override
public DepositReceipt useHeaders(String uri, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
    logger.fine("uri was " + uri);
    logger.fine("isInProgress:" + deposit.isInProgress());
    AuthenticatedUser user = swordAuth.auth(authCredentials);
    DataverseRequest dvRequest = new DataverseRequest(user, httpRequest);
    urlManager.processUrl(uri);
    String targetType = urlManager.getTargetType();
    if (!targetType.isEmpty()) {
        logger.fine("operating on target type: " + urlManager.getTargetType());
        if ("study".equals(targetType)) {
            String globalId = urlManager.getTargetIdentifier();
            if (globalId != null) {
                Dataset dataset = null;
                try {
                    dataset = datasetService.findByGlobalId(globalId);
                } catch (EJBException ex) {
                    throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataset based on global id (" + globalId + ") in URL: " + uri);
                }
                if (dataset != null) {
                    Dataverse dvThatOwnsDataset = dataset.getOwner();
                    boolean doMinorVersionBump = false;
                    // if dataset is unreleased, major version; if released, then check if can be minor
                    if (dataset.isReleased() && dataset.getLatestVersion().isMinorUpdate()) {
                        doMinorVersionBump = true;
                    }
                    PublishDatasetCommand publishDatasetCommand = new PublishDatasetCommand(dataset, dvRequest, doMinorVersionBump);
                    if (!permissionService.isUserAllowedOn(user, publishDatasetCommand, dataset)) {
                        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "User " + user.getDisplayInfo().getTitle() + " is not authorized to modify dataverse " + dvThatOwnsDataset.getAlias());
                    }
                    if (!deposit.isInProgress()) {
                        /**
                         * We are considering a draft version of a study to
                         * be incomplete and are saying that sending
                         * isInProgress=false means the study version is
                         * complete and can be released.
                         *
                         * 9.2. Deposit Incomplete
                         *
                         * "If In-Progress is true, the server SHOULD expect
                         * the client to provide further updates to the item
                         * some undetermined time in the future. Details of
                         * how this is implemented is dependent on the
                         * server's purpose. For example, a repository
                         * system may hold items which are marked
                         * In-Progress in a workspace until such time as a
                         * client request indicates that the deposit is
                         * complete." --
                         * http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#continueddeposit_incomplete
                         */
                        if (!dataset.getLatestVersion().getVersionState().equals(DatasetVersion.VersionState.RELEASED)) {
                            try {
                                dataset = engineSvc.submit(publishDatasetCommand).getDataset();
                            } catch (CommandException ex) {
                                String msg = "Unable to publish dataset: " + ex;
                                logger.severe(msg + ": " + ex.getMessage());
                                throw SwordUtil.throwRegularSwordErrorWithoutStackTrace(msg);
                            }
                            ReceiptGenerator receiptGenerator = new ReceiptGenerator();
                            String baseUrl = urlManager.getHostnamePlusBaseUrlPath(uri);
                            DepositReceipt depositReceipt = receiptGenerator.createDatasetReceipt(baseUrl, dataset);
                            return depositReceipt;
                        } else {
                            throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Latest version of dataset " + globalId + " has already been published.");
                        }
                    } else {
                        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Pass 'In-Progress: false' header to publish a dataset.");
                    }
                } else {
                    throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataset using globalId " + globalId);
                }
            } else {
                throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unable to find globalId for dataset in URL:" + uri);
            }
        } else if ("dataverse".equals(targetType)) {
            String dvAlias = urlManager.getTargetIdentifier();
            if (dvAlias != null) {
                Dataverse dvToRelease = dataverseService.findByAlias(dvAlias);
                if (dvToRelease != null) {
                    PublishDataverseCommand publishDataverseCommand = new PublishDataverseCommand(dvRequest, dvToRelease);
                    if (!permissionService.isUserAllowedOn(user, publishDataverseCommand, dvToRelease)) {
                        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "User " + user.getDisplayInfo().getTitle() + " is not authorized to modify dataverse " + dvAlias);
                    }
                    if (deposit.isInProgress()) {
                        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unpublishing a dataverse is not supported.");
                    }
                    try {
                        engineSvc.submit(publishDataverseCommand);
                        ReceiptGenerator receiptGenerator = new ReceiptGenerator();
                        String baseUrl = urlManager.getHostnamePlusBaseUrlPath(uri);
                        DepositReceipt depositReceipt = receiptGenerator.createDataverseReceipt(baseUrl, dvToRelease);
                        return depositReceipt;
                    } catch (CommandException ex) {
                        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Couldn't publish dataverse " + dvAlias + ": " + ex);
                    }
                } else {
                    throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Could not find dataverse based on alias in URL: " + uri);
                }
            } else {
                throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unable to find dataverse alias in URL: " + uri);
            }
        } else {
            throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "unsupported target type (" + targetType + ") in URL:" + uri);
        }
    } else {
        throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Target type missing from URL: " + uri);
    }
}
Also used : SwordError(org.swordapp.server.SwordError) PublishDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand) Dataset(edu.harvard.iq.dataverse.Dataset) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DepositReceipt(org.swordapp.server.DepositReceipt) PublishDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand) EJBException(javax.ejb.EJBException)

Example 7 with DepositReceipt

use of org.swordapp.server.DepositReceipt in project dataverse by IQSS.

the class ReceiptGenerator method createDataverseReceipt.

DepositReceipt createDataverseReceipt(String baseUrl, Dataverse dataverse) {
    logger.fine("baseUrl was: " + baseUrl);
    DepositReceipt depositReceipt = new DepositReceipt();
    String globalId = dataverse.getAlias();
    String collectionIri = baseUrl + "/collection/dataverse/" + globalId;
    depositReceipt.setSplashUri(collectionIri);
    /**
     * @todo We have to include an "edit" IRI or else we get
     * NullPointerException in getAbderaEntry at
     * https://github.com/swordapp/JavaServer2.0/blob/sword2-server-1.0/src/main/java/org/swordapp/server/DepositReceipt.java#L52
     *
     * Do we want to support a replaceMetadata of dataverses? Probably not.
     * Let's do that with the native API.
     *
     * Typically, we only operate on the "collection" IRI for dataverses, to
     * create a dataset.
     */
    String editIri = baseUrl + "/edit/dataverse/" + globalId;
    depositReceipt.setEditIRI(new IRI(editIri));
    return depositReceipt;
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) DepositReceipt(org.swordapp.server.DepositReceipt)

Example 8 with DepositReceipt

use of org.swordapp.server.DepositReceipt in project dataverse by IQSS.

the class ReceiptGenerator method createDatasetReceipt.

DepositReceipt createDatasetReceipt(String baseUrl, Dataset dataset) {
    logger.fine("baseUrl was: " + baseUrl);
    DepositReceipt depositReceipt = new DepositReceipt();
    String globalId = dataset.getGlobalId();
    String editIri = baseUrl + "/edit/study/" + globalId;
    depositReceipt.setEditIRI(new IRI(editIri));
    /**
     * @todo: should setLocation depend on if an atom entry or a zip file
     * was deposited? (This @todo has been carried over from the DVN 3.x
     * version.)
     */
    depositReceipt.setLocation(new IRI(editIri));
    depositReceipt.setEditMediaIRI(new IRI(baseUrl + "/edit-media/study/" + globalId));
    depositReceipt.setStatementURI("application/atom+xml;type=feed", baseUrl + "/statement/study/" + globalId);
    depositReceipt.addDublinCore("bibliographicCitation", dataset.getLatestVersion().getCitation());
    depositReceipt.setSplashUri(dataset.getPersistentURL());
    return depositReceipt;
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) DepositReceipt(org.swordapp.server.DepositReceipt)

Aggregations

DepositReceipt (org.swordapp.server.DepositReceipt)8 Dataset (edu.harvard.iq.dataverse.Dataset)5 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)5 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)5 SwordError (org.swordapp.server.SwordError)5 Dataverse (edu.harvard.iq.dataverse.Dataverse)4 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 EJBException (javax.ejb.EJBException)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)2 ArrayList (java.util.ArrayList)2 ConstraintViolation (javax.validation.ConstraintViolation)2 ConstraintViolationException (javax.validation.ConstraintViolationException)2 IRI (org.apache.abdera.i18n.iri.IRI)2 ParseException (org.apache.abdera.parser.ParseException)2 SwordAuthException (org.swordapp.server.SwordAuthException)2 SwordEntry (org.swordapp.server.SwordEntry)2 SwordServerException (org.swordapp.server.SwordServerException)2 DataFile (edu.harvard.iq.dataverse.DataFile)1 CommandExecutionException (edu.harvard.iq.dataverse.engine.command.exception.CommandExecutionException)1