use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand in project dataverse by IQSS.
the class ManageGuestbooksPage method saveDataverse.
private void saveDataverse(String successMessage, String failureMessage) {
if (successMessage.isEmpty()) {
successMessage = "dataset.manageGuestbooks.message.editSuccess";
}
if (failureMessage.isEmpty()) {
failureMessage = "dataset.manageGuestbooks.message.editFailure";
}
try {
engineService.submit(new UpdateDataverseCommand(getDataverse(), null, null, dvRequestService.getDataverseRequest(), null));
JsfHelper.addSuccessMessage(JH.localize(successMessage));
} catch (CommandException ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, JH.localize(failureMessage));
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand in project dataverse by IQSS.
the class DataversePage method save.
public String save() {
List<DataverseFieldTypeInputLevel> listDFTIL = new ArrayList<>();
if (editMode != null && editMode.equals(EditMode.INFO)) {
List<MetadataBlock> selectedBlocks = new ArrayList<>();
if (dataverse.isMetadataBlockRoot()) {
dataverse.getMetadataBlocks().clear();
}
for (MetadataBlock mdb : this.allMetadataBlocks) {
if (dataverse.isMetadataBlockRoot() && (mdb.isSelected() || mdb.isRequired())) {
selectedBlocks.add(mdb);
for (DatasetFieldType dsft : mdb.getDatasetFieldTypes()) {
if (dsft.isRequiredDV() && !dsft.isRequired() && ((!dsft.isHasParent() && dsft.isInclude()) || (dsft.isHasParent() && dsft.getParentDatasetFieldType().isInclude()))) {
DataverseFieldTypeInputLevel dftil = new DataverseFieldTypeInputLevel();
dftil.setDatasetFieldType(dsft);
dftil.setDataverse(dataverse);
dftil.setRequired(true);
dftil.setInclude(true);
listDFTIL.add(dftil);
}
if ((!dsft.isHasParent() && !dsft.isInclude()) || (dsft.isHasParent() && !dsft.getParentDatasetFieldType().isInclude())) {
DataverseFieldTypeInputLevel dftil = new DataverseFieldTypeInputLevel();
dftil.setDatasetFieldType(dsft);
dftil.setDataverse(dataverse);
dftil.setRequired(false);
dftil.setInclude(false);
listDFTIL.add(dftil);
}
}
}
}
if (!selectedBlocks.isEmpty()) {
dataverse.setMetadataBlocks(selectedBlocks);
}
if (!dataverse.isFacetRoot()) {
facets.getTarget().clear();
}
}
Command<Dataverse> cmd = null;
// TODO change to Create - for now the page is expecting INFO instead.
Boolean create;
if (dataverse.getId() == null) {
if (session.getUser().isAuthenticated()) {
dataverse.setOwner(ownerId != null ? dataverseService.find(ownerId) : null);
create = Boolean.TRUE;
cmd = new CreateDataverseCommand(dataverse, dvRequestService.getDataverseRequest(), facets.getTarget(), listDFTIL);
} else {
JH.addMessage(FacesMessage.SEVERITY_FATAL, BundleUtil.getStringFromBundle("dataverse.create.authenticatedUsersOnly"));
return null;
}
} else {
create = Boolean.FALSE;
if (editMode != null && editMode.equals(EditMode.FEATURED)) {
cmd = new UpdateDataverseCommand(dataverse, null, featuredDataverses.getTarget(), dvRequestService.getDataverseRequest(), null);
} else {
cmd = new UpdateDataverseCommand(dataverse, facets.getTarget(), null, dvRequestService.getDataverseRequest(), listDFTIL);
}
}
try {
dataverse = commandEngine.submit(cmd);
if (session.getUser() instanceof AuthenticatedUser) {
if (create) {
userNotificationService.sendNotification((AuthenticatedUser) session.getUser(), dataverse.getCreateDate(), Type.CREATEDV, dataverse.getId());
}
}
String message;
if (editMode != null && editMode.equals(EditMode.FEATURED)) {
message = "The featured dataverses for this dataverse have been updated.";
} else {
message = (create) ? BundleUtil.getStringFromBundle("dataverse.create.success", Arrays.asList(settingsWrapper.getGuidesBaseUrl(), systemConfig.getGuidesVersion())) : BundleUtil.getStringFromBundle("dataverse.update.success");
}
JsfHelper.addSuccessMessage(message);
editMode = null;
return returnRedirect();
} catch (CommandException ex) {
logger.log(Level.SEVERE, "Unexpected Exception calling dataverse command", ex);
String errMsg = create ? BundleUtil.getStringFromBundle("dataverse.create.failure") : BundleUtil.getStringFromBundle("dataverse.update.failure");
JH.addMessage(FacesMessage.SEVERITY_FATAL, errMsg);
return null;
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected Exception calling dataverse command", e);
String errMsg = create ? BundleUtil.getStringFromBundle("dataverse.create.failure") : BundleUtil.getStringFromBundle("dataverse.update.failure");
JH.addMessage(FacesMessage.SEVERITY_FATAL, errMsg);
return null;
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand in project dataverse by IQSS.
the class Dataverses method setFacets.
@POST
@Path("{identifier}/facets")
@Produces(MediaType.APPLICATION_JSON)
public /**
* (not publicly documented) API endpoint for assigning facets to a dataverse.
* `curl -X POST -H "X-Dataverse-key: $ADMIN_KEY" http://localhost:8088/api/dataverses/$dv/facets --upload-file foo.json`; where foo.json contains a list of datasetField names,
* works as expected (judging by the UI).
* This triggers a 500 when '-d @foo.json' is used.
*/
Response setFacets(@PathParam("identifier") String dvIdtf, String facetIds) {
List<DatasetFieldType> facets = new LinkedList<>();
for (JsonString facetId : Util.asJsonArray(facetIds).getValuesAs(JsonString.class)) {
DatasetFieldType dsfType = findDatasetFieldType(facetId.getString());
if (dsfType == null) {
return error(Response.Status.BAD_REQUEST, "Can't find dataset field type '" + facetId + "'");
} else if (!dsfType.isFacetable()) {
return error(Response.Status.BAD_REQUEST, "Dataset field type '" + facetId + "' is not facetable");
}
facets.add(dsfType);
}
try {
Dataverse dataverse = findDataverseOrDie(dvIdtf);
// by passing null for Featured Dataverses and DataverseFieldTypeInputLevel, those are not changed
execCommand(new UpdateDataverseCommand(dataverse, facets, null, createDataverseRequest(findUserOrDie()), null));
return ok("Facets of dataverse " + dvIdtf + " updated.");
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand in project dataverse by IQSS.
the class ManageTemplatesPage method saveDataverse.
private void saveDataverse(String successMessage) {
if (successMessage.isEmpty()) {
successMessage = "Template data updated";
}
try {
engineService.submit(new UpdateDataverseCommand(getDataverse(), null, null, dvRequestService.getDataverseRequest(), null));
// JH.addMessage(FacesMessage.SEVERITY_INFO, successMessage);
JsfHelper.addFlashMessage(successMessage);
} catch (CommandException ex) {
String failMessage = "Template update failed";
if (successMessage.equals("The template has been deleted")) {
failMessage = "The dataset template cannot be deleted.";
}
if (successMessage.equals("The template has been selected as the default template for this dataverse")) {
failMessage = "The dataset template cannot be made default.";
}
JH.addMessage(FacesMessage.SEVERITY_FATAL, failMessage);
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseCommand in project dataverse by IQSS.
the class GuestbookPage method save.
public String save() {
boolean create = false;
if (!(guestbook.getCustomQuestions() == null)) {
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq.getQuestionType().equals("text")) {
cq.setCustomQuestionValues(null);
}
}
Iterator<CustomQuestion> cqIt = guestbook.getCustomQuestions().iterator();
while (cqIt.hasNext()) {
CustomQuestion cq = cqIt.next();
if (StringUtils.isBlank(cq.getQuestionString())) {
cqIt.remove();
}
}
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq != null && cq.getQuestionType().equals("options")) {
Iterator<CustomQuestionValue> cqvIt = cq.getCustomQuestionValues().iterator();
while (cqvIt.hasNext()) {
CustomQuestionValue cqv = cqvIt.next();
if (StringUtils.isBlank(cqv.getValueString())) {
cqvIt.remove();
}
}
}
}
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq != null && cq.getQuestionType().equals("options")) {
if (cq.getCustomQuestionValues() == null || cq.getCustomQuestionValues().isEmpty()) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Guestbook Save Failed", " - An Option question requires multiple options. Please complete before saving."));
return null;
}
if (cq.getCustomQuestionValues().size() == 1) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Guestbook Save Failed", " - An Option question requires multiple options. Please complete before saving."));
return null;
}
}
}
int i = 0;
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
int j = 0;
cq.setDisplayOrder(i);
if (cq.getCustomQuestionValues() != null && !cq.getCustomQuestionValues().isEmpty()) {
for (CustomQuestionValue cqv : cq.getCustomQuestionValues()) {
cqv.setDisplayOrder(j);
j++;
}
}
i++;
}
}
Command<Dataverse> cmd;
try {
if (editMode == EditMode.CREATE || editMode == EditMode.CLONE) {
guestbook.setCreateTime(new Timestamp(new Date().getTime()));
guestbook.setUsageCount(new Long(0));
guestbook.setEnabled(true);
dataverse.getGuestbooks().add(guestbook);
cmd = new UpdateDataverseCommand(dataverse, null, null, dvRequestService.getDataverseRequest(), null);
commandEngine.submit(cmd);
create = true;
} else {
cmd = new UpdateDataverseGuestbookCommand(dataverse, guestbook, 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_FATAL, "Guestbook Save Failed", " - " + error.toString()));
logger.info("Guestbook Page EJB Exception. Dataverse: " + dataverse.getName());
logger.info(error.toString());
return null;
} catch (CommandException ex) {
logger.info("Guestbook Page Command Exception. Dataverse: " + dataverse.getName());
logger.info(ex.toString());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Guestbook Save Failed", " - " + ex.toString()));
// logger.severe(ex.getMessage());
}
editMode = null;
String msg = (create) ? "The guestbook has been created." : "The guestbook has been edited and saved.";
JsfHelper.addFlashMessage(msg);
return "/manage-guestbooks.xhtml?dataverseId=" + dataverse.getId() + "&faces-redirect=true";
}
Aggregations