Skip to content

Commit

Permalink
BugID: 1050 - Modifiche Articolo 18
Browse files Browse the repository at this point in the history
  • Loading branch information
mspasiano committed Jan 4, 2013
1 parent 81b3450 commit e5b6fe3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
Expand Up @@ -73,7 +73,7 @@ protected void validate(ActionContext actioncontext, OggettoBulk oggettobulk) th
allegato.getType().equals(AllegatoContrattoDocumentBulk.PROGETTO))
throw new ValidationException("Attenzione: selezionare un File da caricare oppure valorizzare il Link al Progetto.");
}else{
if ((!allegato.isContentStreamPresent() && allegato.getLink() == null) &&
if ((!allegato.isContentStreamPresent() && (allegato.getLink() == null&&allegato.getFile() == null)) &&
allegato.getType().equals(AllegatoContrattoDocumentBulk.PROGETTO))
throw new ValidationException("Attenzione: selezionare un File da caricare oppure valorizzare il Link al Progetto.");
}
Expand Down Expand Up @@ -506,17 +506,20 @@ public OggettoBulk initializeModelForEdit(ActionContext actioncontext,

public String getNomeAllegato(){
AllegatoContrattoDocumentBulk allegato = (AllegatoContrattoDocumentBulk)getCrudArchivioAllegati().getModel();
if (allegato != null && allegato.getNode() != null)
return allegato.getNode().getName();
if (allegato != null && allegato.isNodePresent()){
Node node = contrattoService.getNodeByNodeRef(allegato.getNodeId());
return node.getName();
}
return null;
}

public void scaricaAllegato(ActionContext actioncontext) throws IOException, ServletException {
AllegatoContrattoDocumentBulk allegato = (AllegatoContrattoDocumentBulk)getCrudArchivioAllegati().getModel();
InputStream is = contrattoService.getResource(allegato.getNode());
((HttpActionContext)actioncontext).getResponse().setContentLength(allegato.getNode().getContentLength().intValue());
((HttpActionContext)actioncontext).getResponse().setContentType(allegato.getNode().getContentType());
((HttpActionContext)actioncontext).getResponse().setContentLength(allegato.getNode().getContentLength().intValue());
Node node = contrattoService.getNodeByNodeRef(allegato.getNodeId());
InputStream is = contrattoService.getResource(node);
((HttpActionContext)actioncontext).getResponse().setContentLength(node.getContentLength().intValue());
((HttpActionContext)actioncontext).getResponse().setContentType(node.getContentType());
((HttpActionContext)actioncontext).getResponse().setContentLength(node.getContentLength().intValue());
OutputStream os = ((HttpActionContext)actioncontext).getResponse().getOutputStream();
((HttpActionContext)actioncontext).getResponse().setDateHeader("Expires", 0);
byte[] buffer = new byte[((HttpActionContext)actioncontext).getResponse().getBufferSize()];
Expand All @@ -537,7 +540,7 @@ private void archiviaAllegati(ActionContext actioncontext, ContrattoBulk contrat
for (Iterator<AllegatoContrattoDocumentBulk> iterator = contratto.getArchivioAllegati().deleteIterator(); iterator.hasNext();) {
AllegatoContrattoDocumentBulk allegato = iterator.next();
if (allegato.isToBeDeleted()){
contrattoService.deleteNode(allegato.getNode());
contrattoService.deleteNode(contrattoService.getNodeByNodeRef(allegato.getNodeId()));
allegato.setCrudStatus(OggettoBulk.NORMAL);
}
}
Expand All @@ -560,7 +563,7 @@ private void archiviaAllegati(ActionContext actioncontext, ContrattoBulk contrat
costruisciAlberaturaAlternativa(allegato, node);

allegato.setCrudStatus(OggettoBulk.NORMAL);
allegato.setNode(node);
allegato.setNodeId(node.getId());
} catch (FileNotFoundException e) {
throw handleException(e);
}catch (CmisConstraintException e) {
Expand All @@ -569,10 +572,10 @@ private void archiviaAllegati(ActionContext actioncontext, ContrattoBulk contrat
}else if (allegato.isToBeUpdated()) {
try {
if (allegato.getFile() != null)
contrattoService.updateContent(allegato.getNode().getId(),
contrattoService.updateContent(allegato.getNodeId(),
new FileInputStream(allegato.getFile()),
allegato.getContentType());
contrattoService.updateProperties(allegato, allegato.getNode());
contrattoService.updateProperties(allegato, contrattoService.getNodeByNodeRef(allegato.getNodeId()));
allegato.setCrudStatus(OggettoBulk.NORMAL);
} catch (FileNotFoundException e) {
throw handleException(e);
Expand Down
Expand Up @@ -15,7 +15,6 @@
public class AllegatoContrattoDocumentBulk extends OggettoBulk implements CMISTypeName{
private static final long serialVersionUID = 1L;
private ContrattoBulk contrattoBulk;
private Node node;
private File file;
private String contentType;
private String nome;
Expand All @@ -24,6 +23,9 @@ public class AllegatoContrattoDocumentBulk extends OggettoBulk implements CMISTy
private String type;
private String link;

private BigInteger contentlength;
private String nodeId;

private static final java.util.Dictionary ti_allegatoKeys = new it.cnr.jada.util.OrderedHashtable();

final public static String CONTRATTO = "D:sigla_contratti_attachment:contratto";
Expand Down Expand Up @@ -52,7 +54,16 @@ public static AllegatoContrattoDocumentBulk construct(Node node){

public AllegatoContrattoDocumentBulk(Node node) {
super();
this.node = node;
contentlength = node.getContentLength();
nodeId = node.getId();
}

public String getNodeId() {
return nodeId;
}

public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}

public String parseFilename(String file) {
Expand All @@ -72,13 +83,9 @@ public String parseFilename(String file) {
}

public boolean isNodePresent(){
return getNode() == null;
return nodeId != null;
}

public Node getNode() {
return node;
}

public File getFile() {
return file;
}
Expand Down Expand Up @@ -135,13 +142,10 @@ public void setContrattoBulk(ContrattoBulk contrattoBulk) {
this.contrattoBulk = contrattoBulk;
}

public void setNode(Node node) {
this.node = node;
}

public String getTypeName() {
return getType();
}

@CMISPolicy(name="P:sigla_contratti_aspect:link", property=@CMISProperty(name="sigla_contratti_aspect_link:url"))
public String getLink() {
return link;
Expand All @@ -156,7 +160,7 @@ public boolean isTypeEnabled(){
}

public boolean isContentStreamPresent(){
return node!= null && node.getContentLength().compareTo(BigInteger.ZERO) == 1;
return isNodePresent() && contentlength.compareTo(BigInteger.ZERO) == 1;
}

@CMISProperty(name="cmis:name")
Expand Down

0 comments on commit e5b6fe3

Please sign in to comment.