Search in sources :

Example 66 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class TemplatePage method save.

public String save(String redirectPage) {
    // SEK - removed dead code 1/6/2015
    boolean create = false;
    Command<Void> cmd;
    Long createdId = new Long(0);
    Template created;
    try {
        if (editMode == EditMode.CREATE) {
            template.setCreateTime(new Timestamp(new Date().getTime()));
            template.setUsageCount(new Long(0));
            dataverse.getTemplates().add(template);
            created = commandEngine.submit(new CreateTemplateCommand(template, dvRequestService.getDataverseRequest(), dataverse));
            createdId = created.getId();
            // cmd = new UpdateDataverseCommand(dataverse, null, null, dvRequestService.getDataverseRequest(), null);
            create = true;
        // commandEngine.submit(cmd);
        } else {
            cmd = new UpdateDataverseTemplateCommand(dataverse, template, dvRequestService.getDataverseRequest());
            commandEngine.submit(cmd);
        }
    } catch (EJBException ex) {
        StringBuilder error = new StringBuilder();
        error.append(ex).append(" ");
        error.append(ex.getMessage()).append(" ");
        Throwable cause = ex;
        while (cause.getCause() != null) {
            cause = cause.getCause();
            error.append(cause).append(" ");
            error.append(cause.getMessage()).append(" ");
        }
        // 
        // FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Template Save Failed", " - " + error.toString()));
        System.out.print("dataverse " + dataverse.getName());
        System.out.print("Ejb exception");
        System.out.print(error.toString());
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Template Save Failed");
        return null;
    } catch (CommandException ex) {
        System.out.print("command exception");
        System.out.print(ex.toString());
        // FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Template Save Failed", " - " + ex.toString()));
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Template Save Failed");
        return null;
    // logger.severe(ex.getMessage());
    }
    editMode = null;
    String msg = (create) ? "Template has been created." : "Template has been edited and saved.";
    JsfHelper.addFlashMessage(msg);
    String retString = "";
    if (!redirectPage.isEmpty() && createdId.intValue() > 0) {
        retString = "/template.xhtml?id=" + createdId + "&ownerId=" + dataverse.getId() + "&editMode=LICENSEADD&faces-redirect=true";
    } else {
        retString = "/manage-templates.xhtml?dataverseId=" + dataverse.getId() + "&faces-redirect=true";
    }
    return retString;
}
Also used : CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Timestamp(java.sql.Timestamp) Date(java.util.Date) UpdateDataverseTemplateCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseTemplateCommand) CreateTemplateCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateTemplateCommand) EJBException(javax.ejb.EJBException)

Example 67 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class FileDownloadServiceBean method writeGuestbookResponseRecord.

public void writeGuestbookResponseRecord(GuestbookResponse guestbookResponse) {
    try {
        CreateGuestbookResponseCommand cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), guestbookResponse, guestbookResponse.getDataset());
        commandEngine.submit(cmd);
    } catch (CommandException e) {
    // if an error occurs here then download won't happen no need for response recs...
    }
}
Also used : CreateGuestbookResponseCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateGuestbookResponseCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 68 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class FilePage method save.

public String save() {
    // Validate
    Set<ConstraintViolation> constraintViolations = this.fileMetadata.getDatasetVersion().validate();
    if (!constraintViolations.isEmpty()) {
        // JsfHelper.addFlashMessage(JH.localize("dataset.message.validationError"));
        fileDeleteInProgress = false;
        JH.addMessage(FacesMessage.SEVERITY_ERROR, JH.localize("dataset.message.validationError"));
        // FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validation Error", "See below for details."));
        return "";
    }
    Command<Dataset> cmd;
    try {
        cmd = new UpdateDatasetCommand(editDataset, dvRequestService.getDataverseRequest(), filesToBeDeleted);
        commandEngine.submit(cmd);
    } catch (EJBException ex) {
        StringBuilder error = new StringBuilder();
        error.append(ex).append(" ");
        error.append(ex.getMessage()).append(" ");
        Throwable cause = ex;
        while (cause.getCause() != null) {
            cause = cause.getCause();
            error.append(cause).append(" ");
            error.append(cause.getMessage()).append(" ");
        }
        return null;
    } catch (CommandException ex) {
        fileDeleteInProgress = false;
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
        return null;
    }
    if (fileDeleteInProgress) {
        JsfHelper.addSuccessMessage(JH.localize("file.message.deleteSuccess"));
        fileDeleteInProgress = false;
    } else {
        JsfHelper.addSuccessMessage(JH.localize("file.message.editSuccess"));
    }
    setVersion("DRAFT");
    return "";
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) EJBException(javax.ejb.EJBException) FacesMessage(javax.faces.application.FacesMessage) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)

Example 69 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class FileRecordWriter method updateDatasetVersion.

// utils
/**
 * Update the dataset version using the command engine so permissions and constraints are enforced.
 * Log errors to both the glassfish log and in the job context, as the exit status "failed".
 *
 * @param version dataset version
 */
private void updateDatasetVersion(DatasetVersion version) {
    // update version using the command engine to enforce user permissions and constraints
    if (dataset.getVersions().size() == 1 && version.getVersionState() == DatasetVersion.VersionState.DRAFT) {
        try {
            Command<DatasetVersion> cmd;
            cmd = new UpdateDatasetVersionCommand(new DataverseRequest(user, (HttpServletRequest) null), version);
            commandEngine.submit(cmd);
        } catch (CommandException ex) {
            String commandError = "CommandException updating DatasetVersion from batch job: " + ex.getMessage();
            getJobLogger().log(Level.SEVERE, commandError);
            jobContext.setExitStatus("FAILED");
        }
    } else {
        String constraintError = "ConstraintException updating DatasetVersion form batch job: dataset must be a " + "single version in draft mode.";
        getJobLogger().log(Level.SEVERE, constraintError);
        jobContext.setExitStatus("FAILED");
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) UpdateDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand)

Example 70 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetRequiredPermissions.

@Test
public void testGetRequiredPermissions() {
    CreatePrivateUrlCommand createPrivateUrlCommand = new CreatePrivateUrlCommand(null, null);
    CommandException ex = new CommandException(null, createPrivateUrlCommand);
    List<String> strings = PrivateUrlUtil.getRequiredPermissions(ex);
    assertEquals(Arrays.asList("ManageDatasetPermissions"), strings);
}
Also used : CreatePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Aggregations

CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)86 Dataset (edu.harvard.iq.dataverse.Dataset)21 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)20 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)19 Test (org.junit.Test)16 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)15 EJBException (javax.ejb.EJBException)13 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)12 DataFile (edu.harvard.iq.dataverse.DataFile)11 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)9 ConstraintViolation (javax.validation.ConstraintViolation)9 DatasetThumbnail (edu.harvard.iq.dataverse.dataset.DatasetThumbnail)8 IOException (java.io.IOException)8 Timestamp (java.sql.Timestamp)8 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 FacesMessage (javax.faces.application.FacesMessage)7 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 SwordError (org.swordapp.server.SwordError)6