Skip to content

Commit

Permalink
- Spesometro 2017
Browse files Browse the repository at this point in the history
- Risoluzione anomalie
  • Loading branch information
rosangela.pucciarelli committed Oct 2, 2017
1 parent 6042adc commit 9c97fd6
Show file tree
Hide file tree
Showing 20 changed files with 2,038 additions and 25 deletions.
@@ -0,0 +1,64 @@
package it.cnr.contab.docamm00.actions;

import java.util.GregorianCalendar;

import it.cnr.contab.docamm00.bp.ElaboraFileSpesometroBP;
import it.cnr.contab.docamm00.docs.bulk.VSpesometroNewBulk;
import it.cnr.contab.utenze00.bp.CNRUserContext;
import it.cnr.jada.action.ActionContext;
import it.cnr.jada.action.Forward;
import it.cnr.jada.bulk.FillException;
import it.cnr.jada.comp.ApplicationException;
import it.cnr.jada.comp.ComponentException;
import it.cnr.jada.persistency.IntrospectionException;
import it.cnr.jada.persistency.PersistencyException;

public class ElaboraFileSpesometroAction extends it.cnr.jada.util.action.CRUDAction {
public ElaboraFileSpesometroAction() {
super();
}
public Forward doBringBack(ActionContext context) {
return context.findDefaultForward();
}

public Forward doElaboraFile(ActionContext context) throws ComponentException, PersistencyException, IntrospectionException {
try {
fillModel(context);
ElaboraFileSpesometroBP bp = (ElaboraFileSpesometroBP) context.getBusinessProcess();
bp.setFile(null);
VSpesometroNewBulk dett = (VSpesometroNewBulk)bp.getModel();
if(dett.getNome_file()==null|| dett.getNome_file().length()!=22){
throw new ApplicationException("Indicare un nome di file valido!");
}

if(dett.getDa_data()==null ||dett.getA_data()==null){
throw new ApplicationException("Indicare il periodo di estrazione!");
}
if(dett.getA_data().before(dett.getDa_data()))
throw new ApplicationException("Periodo di estrazione non valido!");

GregorianCalendar dataDa = new GregorianCalendar();
dataDa.setTime(new java.util.Date( dett.getDa_data().getTime()));
int anno= dataDa.get(GregorianCalendar.YEAR);
dataDa.setTime(new java.util.Date( dett.getA_data().getTime()));
int anno_a= dataDa.get(GregorianCalendar.YEAR);

if(CNRUserContext.getEsercizio(context.getUserContext()).intValue() !=anno || CNRUserContext.getEsercizio(context.getUserContext()).intValue() !=anno_a)
throw new ApplicationException("Periodo di estrazione non coerente con esercizio di scrivania!");
if(dett.getTipo()==null)
throw new ApplicationException("Indicare il tipo!");

try {
bp.doElaboraFile(context,dett);
} catch (Exception e) {
return handleException(context, e);
}
bp.setMessage("Elaborazione completata.");
return context.findDefaultForward();
} catch (Exception e) {
return handleException(context,e);
}

}

}
@@ -0,0 +1,160 @@
package it.cnr.contab.docamm00.bp;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;

import it.cnr.contab.anagraf00.core.bulk.AnagraficoBulk;
import it.cnr.contab.anagraf00.ejb.AnagraficoComponentSession;
import it.cnr.contab.docamm00.docs.bulk.VSpesometroNewBulk;
import it.cnr.contab.docamm00.ejb.ElaboraFileIntraComponentSession;
import it.cnr.jada.action.*;
import it.cnr.jada.comp.ApplicationException;
import it.cnr.jada.comp.ComponentException;
import it.cnr.jada.persistency.IntrospectionException;
import it.cnr.jada.persistency.PersistencyException;
import it.cnr.jada.util.action.SimpleCRUDBP;
import it.cnr.jada.util.jsp.Button;
import it.cnr.jada.util.jsp.JSPUtils;
import it.gov.agenziaentrate.ivaservizi.docs.xsd.fatture.v2.DatiFatturaType;
import it.gov.agenziaentrate.ivaservizi.docs.xsd.fatture.v2.NazioneITType;


public class ElaboraFileSpesometroBP extends SimpleCRUDBP {

public ElaboraFileSpesometroBP() {
super();
}
public ElaboraFileSpesometroBP(String function) {
super(function);
}
public ElaboraFileIntraComponentSession createComponentSession() throws BusinessProcessException
{
return (ElaboraFileIntraComponentSession)createComponentSession("CNRDOCAMM00_EJB_ElaboraFileIntraComponentSession",ElaboraFileIntraComponentSession.class);
}
public boolean isScaricaButtonEnabled() {
if(getFile()!=null)
return true;
else
return false;
}


protected it.cnr.jada.util.jsp.Button[] createToolbar() {

it.cnr.jada.util.jsp.Button[] toolbar = new it.cnr.jada.util.jsp.Button[2];
int i = 0;
toolbar[i++] = new it.cnr.jada.util.jsp.Button(it.cnr.jada.util.Config.getHandler().getProperties(getClass()),"Toolbar.start");
toolbar[i++] = new it.cnr.jada.util.jsp.Button(it.cnr.jada.util.Config.getHandler().getProperties(getClass()),"Toolbar.download");

return toolbar;
}

private String file;
private Integer conta=0;
private String nome_file;
public void doElaboraFile(ActionContext context,VSpesometroNewBulk dett) throws BusinessProcessException, ComponentException, PersistencyException, IntrospectionException, JAXBException {
try{
File f = new File(System.getProperty("tmp.dir.SIGLAWeb")+"/tmp/",
dett.getNome_file()+".xml");

FileOutputStream fileOutputStream = new FileOutputStream(f);
ElaboraFileIntraComponentSession component = createComponentSession();
if (component.EstraiLista(context.getUserContext(), dett).size() >1000)
throw new it.cnr.jada.comp.ApplicationException("Sono state selezionati troppi dati, diminuire intervallo!");
JAXBElement<DatiFatturaType> datifatturaType = component.creaDatiFatturaType(context.getUserContext(), dett);

JAXBContext jaxbContext = JAXBContext.newInstance("it.gov.agenziaentrate.ivaservizi.docs.xsd.fatture.v2");

jaxbContext.createMarshaller().marshal(datifatturaType, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
setFile("/tmp/"+f.getName());

} catch (FileNotFoundException e) {
throw new ApplicationException("File non trovato!");
}
catch (IllegalArgumentException e) {
throw new ApplicationException("Formato file non valido!");
}
catch (IOException e) {
throw new ApplicationException("Errore nella scrittura del file!");
}
}
/**
* @param s Stringa in Input
* @param allineamento del testo "D" Destra - "S" Sinistra
* @param dimensione richiesta del campo
* @param riempimento carattere di riempimento per raggiungere la dimensione richiesta
* @return La stringa formattata e riempita con l'allinemento richiesto
*/
public String Formatta(String s, String allineamento,Integer dimensione,String riempimento){
if (s==null)
s=riempimento;
if (s.length()< dimensione){
if (allineamento.compareTo("D")==0){
while (s.length()<dimensione)
s=riempimento+s;
return s.toUpperCase();
}
else
{
while (s.length()<dimensione)
s=s+riempimento;
return s.toUpperCase();
}
}else if (s.length()> dimensione){
s=s.substring(0,dimensione);
return s.toUpperCase();
}
return s.toUpperCase();
}

public void writeToolbar(PageContext pagecontext) throws IOException, ServletException {
Button[] toolbar = getToolbar();
if(getFile()!=null){
HttpServletResponse httpservletresp = (HttpServletResponse)pagecontext.getResponse();
HttpServletRequest httpservletrequest = (HttpServletRequest)pagecontext.getRequest();
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append(pagecontext.getRequest().getScheme());
stringbuffer.append("://");
stringbuffer.append(pagecontext.getRequest().getServerName());
stringbuffer.append(':');
stringbuffer.append(pagecontext.getRequest().getServerPort());
stringbuffer.append(JSPUtils.getAppRoot(httpservletrequest));
toolbar[1].setHref("javascript:doPrint('"+stringbuffer+getFile()+ "')");
}
super.writeToolbar(pagecontext);
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
@Override
protected void init(Config config, ActionContext context)
throws BusinessProcessException {
try {
super.init(config,context);
AnagraficoComponentSession sess = (AnagraficoComponentSession)it.cnr.jada.util.ejb.EJBCommonServices.createEJB("CNRANAGRAF00_EJB_AnagraficoComponentSession", AnagraficoComponentSession.class);
AnagraficoBulk ente = sess.getAnagraficoEnte(context.getUserContext());

VSpesometroNewBulk bulk = new VSpesometroNewBulk();
bulk.setNome_file(NazioneITType.IT+ente.getCodice_fiscale()+"_"+"DF"+"_"+"00001");
setModel(context,bulk);
} catch(Throwable e) {
throw handleException(e);
}

}
}

0 comments on commit 9c97fd6

Please sign in to comment.