diff --git a/scripts/api/data/metadatablocks/citation.tsv b/scripts/api/data/metadatablocks/citation.tsv index d0f2f748971..e44312f7f60 100644 --- a/scripts/api/data/metadatablocks/citation.tsv +++ b/scripts/api/data/metadatablocks/citation.tsv @@ -93,8 +93,8 @@ contributorType Supervisor 13 contributorType Work Package Leader 14 contributorType Other 15 - authorIdentifierScheme ISNI 0 - authorIdentifierScheme ORCID 1 + authorIdentifierScheme ORCID 0 + authorIdentifierScheme ISNI 1 language Abkhaz 0 language Afar 1 language Afrikaans 2 @@ -279,4 +279,4 @@ language Yoruba 181 language Zhuang, Chuang 182 language Zulu 183 - language Not applicable 184 \ No newline at end of file + language Not applicable 184 diff --git a/src/main/java/edu/harvard/iq/dataverse/Template.java b/src/main/java/edu/harvard/iq/dataverse/Template.java index 97f869cbd04..16cbe73489b 100644 --- a/src/main/java/edu/harvard/iq/dataverse/Template.java +++ b/src/main/java/edu/harvard/iq/dataverse/Template.java @@ -7,6 +7,7 @@ import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.persistence.CascadeType; @@ -18,6 +19,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import javax.validation.constraints.Size; import org.hibernate.validator.constraints.NotBlank; /** @@ -47,6 +49,7 @@ public Long getId() { } @NotBlank(message = "Please enter a name.") + @Size(max = 255, message = "Name must be at most 255 characters.") private String name; public String getName() { @@ -276,6 +279,24 @@ public void setDatasetFields(List datasetFields) { this.datasetFields = datasetFields; } + public List getFlatDatasetFields() { + return getFlatDatasetFields(getDatasetFields()); + } + + private List getFlatDatasetFields(List dsfList) { + List retList = new LinkedList(); + for (DatasetField dsf : dsfList) { + retList.add(dsf); + if (dsf.getDatasetFieldType().isCompound()) { + for (DatasetFieldCompoundValue compoundValue : dsf.getDatasetFieldCompoundValues()) { + retList.addAll(getFlatDatasetFields(compoundValue.getChildDatasetFields())); + } + + } + } + return retList; + } + @Override public int hashCode() { int hash = 0; diff --git a/src/main/java/edu/harvard/iq/dataverse/TemplatePage.java b/src/main/java/edu/harvard/iq/dataverse/TemplatePage.java index 0d7dd4ff40e..a53ecf230ec 100644 --- a/src/main/java/edu/harvard/iq/dataverse/TemplatePage.java +++ b/src/main/java/edu/harvard/iq/dataverse/TemplatePage.java @@ -6,6 +6,7 @@ import edu.harvard.iq.dataverse.engine.command.impl.UpdateDateverseTemplateCommand; import java.sql.Timestamp; import java.util.Date; +import java.util.Set; import javax.ejb.EJB; import javax.ejb.EJBException; import javax.faces.application.FacesMessage; @@ -13,6 +14,10 @@ import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; /** * @@ -110,6 +115,34 @@ public void edit(TemplatePage.EditMode editMode) { } public String save() { + + boolean dontSave = false; + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + for (DatasetField dsf : template.getFlatDatasetFields()) { + dsf.setValidationMessage(null); // clear out any existing validation message + Set> constraintViolations = validator.validate(dsf); + for (ConstraintViolation constraintViolation : constraintViolations) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validation Error", constraintViolation.getMessage())); + dsf.setValidationMessage(constraintViolation.getMessage()); + dontSave = true; + break; // currently only support one message, so we can break out of the loop after the first constraint violation + } + for (DatasetFieldValue dsfv : dsf.getDatasetFieldValues()) { + dsfv.setValidationMessage(null); // clear out any existing validation message + Set> constraintViolations2 = validator.validate(dsfv); + for (ConstraintViolation constraintViolation : constraintViolations2) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validation Error", constraintViolation.getMessage())); + dsfv.setValidationMessage(constraintViolation.getMessage()); + dontSave = true; + break; // currently only support one message, so we can break out of the loop after the first constraint violation + } + } + } + if (dontSave) { + return ""; + } + Command cmd; try { if (editMode == EditMode.CREATE) { diff --git a/src/main/java/edu/harvard/iq/dataverse/dataaccess/TabularSubsetGenerator.java b/src/main/java/edu/harvard/iq/dataverse/dataaccess/TabularSubsetGenerator.java index 681c7ac2cf0..6594ef2ac4e 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataaccess/TabularSubsetGenerator.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataaccess/TabularSubsetGenerator.java @@ -562,7 +562,7 @@ private File generateRotatedImage (File tabfile, int varcount, int casecount) th int MAX_OUTPUT_STREAMS = 32; int MAX_BUFFERED_BYTES = 10 * 1024 * 1024; // 10 MB - for now? - int MAX_COLUMN_BUFFER = 8192; + int MAX_COLUMN_BUFFER = 8 * 1024; // offsetHeader will contain the byte offsets of the individual column // vectors in the final rotated image file @@ -604,9 +604,18 @@ private File generateRotatedImage (File tabfile, int varcount, int casecount) th tokensize = token.getBytes().length; if (bufferedSizes[varindex]+tokensize > MAX_COLUMN_BUFFER) { // fill the buffer and dump its contents into the temp file: + // (do note that there may be *several* MAX_COLUMN_BUFFERs + // worth of bytes in the token!) + + int tokenoffset = 0; + if (bufferedSizes[varindex] != MAX_COLUMN_BUFFER) { - System.arraycopy(token.getBytes(), 0, bufferedColumns[varindex], bufferedSizes[varindex], MAX_COLUMN_BUFFER-bufferedSizes[varindex]); - } + tokenoffset = MAX_COLUMN_BUFFER-bufferedSizes[varindex]; + System.arraycopy(token.getBytes(), 0, bufferedColumns[varindex], bufferedSizes[varindex], tokenoffset); + } // (otherwise the buffer is already full, and we should + // simply dump it into the temp file, without adding any + // extra bytes to it) + File bufferTempFile = columnTempFiles[varindex]; if (bufferTempFile == null) { bufferTempFile = File.createTempFile("columnBufferFile", "bytes"); @@ -618,18 +627,29 @@ private File generateRotatedImage (File tabfile, int varcount, int casecount) th BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream (bufferTempFile, true)); outputStream.write(bufferedColumns[varindex], 0, MAX_COLUMN_BUFFER); cachedfileSizes[varindex] += MAX_COLUMN_BUFFER; + + // keep writing MAX_COLUMN_BUFFER-size chunks of bytes into + // the temp file, for as long as there's more than MAX_COLUMN_BUFFER + // bytes left in the token: + + while (tokensize - tokenoffset > MAX_COLUMN_BUFFER) { + outputStream.write(token.getBytes(), tokenoffset, MAX_COLUMN_BUFFER); + cachedfileSizes[varindex] += MAX_COLUMN_BUFFER; + tokenoffset += MAX_COLUMN_BUFFER; + } + outputStream.close(); // buffer the remaining bytes and reset the buffered // byte counter: System.arraycopy(token.getBytes(), - MAX_COLUMN_BUFFER-bufferedSizes[varindex], + tokenoffset, bufferedColumns[varindex], 0, - bufferedSizes[varindex] + tokensize - MAX_COLUMN_BUFFER); + tokensize - tokenoffset); - bufferedSizes[varindex] = bufferedSizes[varindex] + tokensize - MAX_COLUMN_BUFFER; + bufferedSizes[varindex] = tokensize - tokenoffset; } else { // continue buffering @@ -803,7 +823,7 @@ private void reverseRotatedImage (File rotfile, int varcount, int casecount) thr /** * main() method, for testing - * usage: java edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator testfile.tab varcount casecount + * usage: java edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator testfile.tab varcount casecount column type * make sure the CLASSPATH contains ... * */