Search in sources :

Example 21 with CommandException

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

the class ManageGroupsPage method deleteGroup.

public void deleteGroup() {
    if (selectedGroup != null) {
        explicitGroups.remove(selectedGroup);
        try {
            engineService.submit(new DeleteExplicitGroupCommand(dvRequestService.getDataverseRequest(), selectedGroup));
            JsfHelper.addFlashMessage("The group has been deleted.");
        } catch (CommandException ex) {
            String failMessage = "The explicit group cannot be deleted.";
            JH.addMessage(FacesMessage.SEVERITY_FATAL, failMessage);
        }
    } else {
        logger.info("Selected group is null");
    }
}
Also used : DeleteExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.DeleteExplicitGroupCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 22 with CommandException

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

the class RolePermissionFragment method assignRole.

private void assignRole(RoleAssignee ra, DataverseRole r) {
    try {
        String privateUrlToken = null;
        commandEngine.submit(new AssignRoleCommand(ra, r, dvObject, dvRequestService.getDataverseRequest(), privateUrlToken));
        JH.addMessage(FacesMessage.SEVERITY_INFO, "Role " + r.getName() + " assigned to " + ra.getDisplayInfo().getTitle() + " on " + StringEscapeUtils.escapeHtml(dvObject.getDisplayName()));
    } catch (CommandException ex) {
        JH.addMessage(FacesMessage.SEVERITY_ERROR, "Can't assign role: " + ex.getMessage());
    }
}
Also used : CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) AssignRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand)

Example 23 with CommandException

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

the class RolePermissionFragment method revokeRole.

public void revokeRole(Long roleAssignmentId) {
    try {
        commandEngine.submit(new RevokeRoleCommand(em.find(RoleAssignment.class, roleAssignmentId), dvRequestService.getDataverseRequest()));
        JH.addMessage(FacesMessage.SEVERITY_INFO, "Role assignment revoked successfully");
    } catch (PermissionException ex) {
        JH.addMessage(FacesMessage.SEVERITY_ERROR, "Cannot revoke role assignment - you're missing permission", ex.getRequiredPermissions().toString());
        logger.log(Level.SEVERE, "Error revoking role assignment: " + ex.getMessage(), ex);
    } catch (CommandException ex) {
        JH.addMessage(FacesMessage.SEVERITY_ERROR, "Cannot revoke role assignment: " + ex.getMessage());
        logger.log(Level.SEVERE, "Error revoking role assignment: " + ex.getMessage(), ex);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) RevokeRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.RevokeRoleCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 24 with CommandException

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

the class HarvestingClientsPage method saveClient.

// this saves an existing client that the user has edited:
public void saveClient(ActionEvent ae) {
    HarvestingClient harvestingClient = getSelectedClient();
    if (harvestingClient == null) {
    // TODO:
    // tell the user somehow that the client cannot be saved, and advise
    // them to save the settings they have entered.
    // as of now - we will show an error message, but only after the
    // edit form has been closed.
    }
    // nickname is not editable for existing clients:
    // harvestingClient.setName(newNickname);
    harvestingClient.setHarvestingUrl(newHarvestingUrl);
    harvestingClient.setHarvestingSet(newOaiSet);
    harvestingClient.setMetadataPrefix(newMetadataFormat);
    harvestingClient.setHarvestStyle(newHarvestingStyle);
    if (isNewHarvestingScheduled()) {
        harvestingClient.setScheduled(true);
        if (isNewHarvestingScheduledWeekly()) {
            harvestingClient.setSchedulePeriod(HarvestingClient.SCHEDULE_PERIOD_WEEKLY);
            if (getWeekDayNumber() == null) {
            // create a "week day is required..." error message, etc.
            // but we may be better off not even giving them an opportunity
            // to leave the field blank - ?
            }
            harvestingClient.setScheduleDayOfWeek(getWeekDayNumber());
        } else {
            harvestingClient.setSchedulePeriod(HarvestingClient.SCHEDULE_PERIOD_DAILY);
        }
        if (getHourOfDay() == null) {
        // see the comment above, about the day of week. same here.
        }
        harvestingClient.setScheduleHourOfDay(getHourOfDay());
    } else {
        harvestingClient.setScheduled(false);
    }
    try {
        harvestingClient = engineService.submit(new UpdateHarvestingClientCommand(dvRequestService.getDataverseRequest(), harvestingClient));
        configuredHarvestingClients = harvestingClientService.getAllHarvestingClients();
        if (!harvestingClient.isScheduled()) {
            dataverseTimerService.removeHarvestTimer(harvestingClient);
        }
        JsfHelper.addSuccessMessage("Succesfully updated harvesting client " + harvestingClient.getName());
    } catch (CommandException ex) {
        logger.log(Level.WARNING, "Failed to save harvesting client", ex);
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to save harvesting client", ex.getMessage());
    } catch (Exception ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Failed to save harvesting client (reason unknown).");
        logger.log(Level.SEVERE, "Failed to save harvesting client (reason unknown)." + ex.getMessage(), ex);
    }
    setPageMode(PageMode.VIEW);
}
Also used : UpdateHarvestingClientCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateHarvestingClientCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 25 with CommandException

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

the class HarvestingClientsPage method createClient.

public void createClient(ActionEvent ae) {
    // will be set as type OAI by default
    HarvestingClient newHarvestingClient = new HarvestingClient();
    newHarvestingClient.setName(newNickname);
    if (getSelectedDestinationDataverse() == null) {
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to create a new Harvesting Client configuration: no destination dataverse selected.");
    }
    newHarvestingClient.setDataverse(getSelectedDestinationDataverse());
    if (getSelectedDestinationDataverse().getHarvestingClientConfigs() == null) {
        getSelectedDestinationDataverse().setHarvestingClientConfigs(new ArrayList<>());
    }
    getSelectedDestinationDataverse().getHarvestingClientConfigs().add(newHarvestingClient);
    newHarvestingClient.setHarvestingUrl(newHarvestingUrl);
    if (!StringUtils.isEmpty(newOaiSet)) {
        newHarvestingClient.setHarvestingSet(newOaiSet);
    }
    newHarvestingClient.setMetadataPrefix(newMetadataFormat);
    newHarvestingClient.setHarvestStyle(newHarvestingStyle);
    if (isNewHarvestingScheduled()) {
        newHarvestingClient.setScheduled(true);
        if (isNewHarvestingScheduledWeekly()) {
            newHarvestingClient.setSchedulePeriod(HarvestingClient.SCHEDULE_PERIOD_WEEKLY);
            if (getWeekDayNumber() == null) {
            // create a "week day is required..." error message, etc.
            // but we may be better off not even giving them an opportunity
            // to leave the field blank - ?
            }
            newHarvestingClient.setScheduleDayOfWeek(getWeekDayNumber());
        } else {
            newHarvestingClient.setSchedulePeriod(HarvestingClient.SCHEDULE_PERIOD_DAILY);
        }
        if (getHourOfDay() == null) {
        // see the comment above, about the day of week. same here.
        }
        newHarvestingClient.setScheduleHourOfDay(getHourOfDay());
    }
    // make default archive url (used to generate links pointing back to the
    // archival sources, when harvested datasets are displayed in search results),
    // from the harvesting url:
    newHarvestingClient.setArchiveUrl(makeDefaultArchiveUrl());
    // set default description - they can customize it as they see fit:
    newHarvestingClient.setArchiveDescription(JH.localize("harvestclients.viewEditDialog.archiveDescription.default.generic"));
    try {
        newHarvestingClient = engineService.submit(new CreateHarvestingClientCommand(dvRequestService.getDataverseRequest(), newHarvestingClient));
        configuredHarvestingClients = harvestingClientService.getAllHarvestingClients();
        // NO, we no longer create timers here. It is the job of the Mother Timer!
        // dataverseTimerService.createHarvestTimer(newHarvestingClient);
        String successMessage = JH.localize("harvestclients.newClientDialog.success");
        successMessage = successMessage.replace("{0}", newHarvestingClient.getName());
        JsfHelper.addSuccessMessage(successMessage);
    }/* TODO: (?) add a dedicated "NameAlreadyExists" exception for the 
             create client command? 
          catch ( CreateHarvestingClientCommand.NicknameAlreadyExistsException naee ) {
            FacesContext.getCurrentInstance().addMessage(newHarvestingClient.getName(),
                           new FacesMessage( FacesMessage.SEVERITY_ERROR, naee.getMessage(), null));

        }*/
     catch (CommandException ex) {
        logger.log(Level.WARNING, "Harvesting client creation command failed", ex);
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Harvesting Client creation command failed.", ex.getMessage());
    } catch (Exception ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Harvesting client creation failed (reason unknown).");
        logger.log(Level.SEVERE, "Harvesting client creation failed (reason unknown)." + ex.getMessage(), ex);
    }
    setPageMode(PageMode.VIEW);
}
Also used : CreateHarvestingClientCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateHarvestingClientCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

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