Search in sources :

Example 1 with CreateTemplateCommand

use of edu.harvard.iq.dataverse.engine.command.impl.CreateTemplateCommand in project dataverse by IQSS.

the class ManageTemplatesPage method cloneTemplate.

public String cloneTemplate(Template templateIn) {
    Template newOne = templateIn.cloneNewTemplate(templateIn);
    String name = "Copy of " + templateIn.getName();
    newOne.setName(name);
    newOne.setUsageCount(new Long(0));
    newOne.setCreateTime(new Timestamp(new Date().getTime()));
    dataverse.getTemplates().add(newOne);
    templates.add(newOne);
    Template created;
    try {
        created = engineService.submit(new CreateTemplateCommand(newOne, dvRequestService.getDataverseRequest(), dataverse));
        saveDataverse("");
        String msg = "The template has been copied";
        JsfHelper.addFlashMessage(msg);
        return "/template.xhtml?id=" + created.getId() + "&ownerId=" + dataverse.getId() + "&editMode=METADATA&faces-redirect=true";
    } catch (CommandException ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Template could not be copied. ");
    }
    return "";
}
Also used : CreateTemplateCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateTemplateCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 2 with CreateTemplateCommand

use of edu.harvard.iq.dataverse.engine.command.impl.CreateTemplateCommand 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)

Aggregations

CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 CreateTemplateCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateTemplateCommand)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 UpdateDataverseTemplateCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseTemplateCommand)1 EJBException (javax.ejb.EJBException)1