Skip to content

Commit

Permalink
Add case evidence filename and content type to repo
Browse files Browse the repository at this point in the history
Fixes issue with downloaded case evidence files not containing an extension or valid content type header
  • Loading branch information
bpowers1215 committed Nov 17, 2017
1 parent b3c6b17 commit cd4ef13
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
Expand Up @@ -84,7 +84,11 @@ public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}

public void setContentType(String contentType) {
this.contentType = contentType;
}
}
Expand Up @@ -44,6 +44,8 @@ public class UploadDownloadPanel extends InputPanel {
private static final String ID_BUTTON_DOWNLOAD = "download";
private static final String ID_BUTTON_DELETE = "remove";
private static final String ID_INPUT_FILE = "fileInput";
private String downloadFileName = null;
private String downloadContentType = "text/plain";

public UploadDownloadPanel(String id, boolean isReadOnly) {
super(id);
Expand Down Expand Up @@ -79,12 +81,14 @@ public boolean isVisible() {
add(fileUpload);

final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {
@Override
protected InputStream initStream() {
return getStream();
}

@Override
protected InputStream initStream() {
return getStream();
}
};
downloadBehavior.setContentType(getDownloadContentType());
downloadBehavior.setFileName(getDownloadFileName());
add(downloadBehavior);

add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {
Expand Down Expand Up @@ -153,9 +157,17 @@ public void uploadFileFailed(AjaxRequestTarget target) {

public void updateValue(byte[] file) {
}

public InputStream getStream() {
return null;
return null;
}

public String getDownloadFileName() {
return downloadFileName;
}

public String getDownloadContentType() {
return downloadContentType;
}

private void downloadPerformed(AjaxDownloadBehaviorFromStream downloadBehavior,
Expand Down
Expand Up @@ -223,11 +223,19 @@ private void initLayout() {
mainForm.add(new Label(ID_CASE_WORK_ITEM_DEADLINE, new PropertyModel<>(caseWorkItemDtoModel, CaseWorkItemDto.F_DEADLINE)));
mainForm.add(new Label(ID_CASE_WORK_ITEM_OUTCOME, new PropertyModel<>(caseWorkItemDtoModel, CaseWorkItemDto.F_OUTCOME)));
mainForm.add(new Label(ID_CASE_WORK_ITEM_COMMENT, new PropertyModel<>(caseWorkItemDtoModel, CaseWorkItemDto.F_COMMENT)));
Panel evidencePanel = new UploadDownloadPanel(ID_CASE_WORK_ITEM_EVIDENCE, true){
UploadDownloadPanel evidencePanel = new UploadDownloadPanel(ID_CASE_WORK_ITEM_EVIDENCE, true){
@Override
public InputStream getStream() {
return new ByteArrayInputStream(caseWorkItemDtoModel.getObject().getEvidence());
}
@Override
public String getDownloadFileName() {
return caseWorkItemDtoModel.getObject().getEvidenceFilename();
}
@Override
public String getDownloadContentType() {
return caseWorkItemDtoModel.getObject().getEvidenceContentType();
}
};
evidencePanel.add(new VisibleEnableBehaviour() {
@Override
Expand Down Expand Up @@ -316,7 +324,9 @@ private void closeCaseWorkItemPerformed(AjaxRequestTarget target) {
if (evidenceUploadField != null) {
FileUpload evidence = evidenceUploadField.getFileUpload();
if (evidence != null) {
output = output.evidence(evidence.getBytes());
String filename = evidence.getClientFileName();
String contentType = evidence.getContentType();
output = output.evidence(evidence.getBytes()).evidenceContentType(contentType).evidenceFilename(filename);
}
}
cms.completeWorkItem(caseId, caseWorkItemId, output, task, result);
Expand Down
Expand Up @@ -111,6 +111,14 @@ public byte[] getEvidence() {
return WorkItemTypeUtil.getEvidence(workItem);
}

public String getEvidenceFilename() {
return WorkItemTypeUtil.getEvidenceFilename(workItem);
}

public String getEvidenceContentType() {
return WorkItemTypeUtil.getEvidenceContentType(workItem);
}

public void setEvidence(byte[] value) {
if (workItem.getOutput() == null) {
workItem.beginOutput().evidence(value);
Expand Down
Expand Up @@ -48,6 +48,22 @@ public static byte[] getEvidence(AbstractWorkItemOutputType output) {
return output != null ? output.getEvidence() : null;
}

public static String getEvidenceFilename(AbstractWorkItemType workItem) {
return getEvidenceFilename(getOutput(workItem));
}

public static String getEvidenceFilename(AbstractWorkItemOutputType output) {
return output != null ? output.getEvidenceFilename() : null;
}

public static String getEvidenceContentType(AbstractWorkItemType workItem) {
return getEvidenceContentType(getOutput(workItem));
}

public static String getEvidenceContentType(AbstractWorkItemOutputType output) {
return output != null ? output.getEvidenceContentType() : null;
}

public static String getOutcome(AbstractWorkItemOutputType output) {
return output != null ? output.getOutcome() : null;
}
Expand Down
Expand Up @@ -297,6 +297,8 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="evidenceFilename" type="xsd:string" minOccurs="0" />
<xsd:element name="evidenceContentType" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>

Expand Down

0 comments on commit cd4ef13

Please sign in to comment.