List of usage examples for javax.xml.bind JAXBElement getValue
public T getValue()
Return the content model and attribute values for this element.
See #isNil() for a description of a property constraint when this value is null
From source file:org.apache.taverna.scufl2.translator.t2flow.T2FlowParser.java
@SuppressWarnings("unchecked") public WorkflowBundle parseT2Flow(File t2File) throws IOException, ReaderException, JAXBException { JAXBElement<org.apache.taverna.scufl2.xml.t2flow.jaxb.Workflow> root = (JAXBElement<org.apache.taverna.scufl2.xml.t2flow.jaxb.Workflow>) getUnmarshaller() .unmarshal(t2File);//ww w . ja va2s. c om return parseT2Flow(root.getValue()); }
From source file:org.apache.taverna.scufl2.translator.t2flow.T2FlowParser.java
@SuppressWarnings("unchecked") public WorkflowBundle parseT2Flow(InputStream t2File) throws IOException, JAXBException, ReaderException { JAXBElement<org.apache.taverna.scufl2.xml.t2flow.jaxb.Workflow> root = (JAXBElement<org.apache.taverna.scufl2.xml.t2flow.jaxb.Workflow>) getUnmarshaller() .unmarshal(t2File);//from ww w. j a va 2 s. c o m return parseT2Flow(root.getValue()); }
From source file:it.govpay.core.business.Pagamento.java
public AvviaTransazioneDTOResponse avviaTransazione(AvviaTransazioneDTO dto) throws GovPayException, ServiceException { GpContext ctx = GpThreadLocal.get(); List<Versamento> versamenti = new ArrayList<Versamento>(); for (Object v : dto.getVersamentoOrVersamentoRef()) { Versamento versamentoModel = null; if (v instanceof it.govpay.servizi.commons.Versamento) { it.govpay.servizi.commons.Versamento versamento = (it.govpay.servizi.commons.Versamento) v; ctx.log("rpt.acquisizioneVersamento", versamento.getCodApplicazione(), versamento.getCodVersamentoEnte()); versamentoModel = VersamentoUtils .toVersamentoModel((it.govpay.servizi.commons.Versamento) versamento, this); versamentoModel.setIuvProposto(versamento.getIuv()); } else {/*ww w. j av a2 s .c o m*/ it.govpay.servizi.commons.VersamentoKey versamento = (it.govpay.servizi.commons.VersamentoKey) v; String codDominio = null, codApplicazione = null, codVersamentoEnte = null, iuv = null, bundlekey = null, codUnivocoDebitore = null; Iterator<JAXBElement<String>> iterator = versamento.getContent().iterator(); while (iterator.hasNext()) { JAXBElement<String> element = iterator.next(); if (element.getName().equals(VersamentoUtils._VersamentoKeyBundlekey_QNAME)) { bundlekey = element.getValue(); } if (element.getName().equals(VersamentoUtils._VersamentoKeyCodUnivocoDebitore_QNAME)) { codUnivocoDebitore = element.getValue(); } if (element.getName().equals(VersamentoUtils._VersamentoKeyCodApplicazione_QNAME)) { codApplicazione = element.getValue(); } if (element.getName().equals(VersamentoUtils._VersamentoKeyCodDominio_QNAME)) { codDominio = element.getValue(); } if (element.getName().equals(VersamentoUtils._VersamentoKeyCodVersamentoEnte_QNAME)) { codVersamentoEnte = element.getValue(); } if (element.getName().equals(VersamentoUtils._VersamentoKeyIuv_QNAME)) { iuv = element.getValue(); } } it.govpay.core.business.Versamento versamentoBusiness = new it.govpay.core.business.Versamento( this); versamentoModel = versamentoBusiness.chiediVersamento(codApplicazione, codVersamentoEnte, bundlekey, codUnivocoDebitore, codDominio, iuv); } if (!versamentoModel.getUo(this).isAbilitato()) { throw new GovPayException( "Il pagamento non puo' essere avviato poiche' uno dei versamenti risulta associato ad una unita' operativa disabilitata [Uo:" + versamentoModel.getUo(this).getCodUo() + "].", EsitoOperazione.UOP_001, versamentoModel.getUo(this).getCodUo()); } if (!versamentoModel.getUo(this).getDominio(this).isAbilitato()) { throw new GovPayException( "Il pagamento non puo' essere avviato poiche' uno dei versamenti risulta associato ad un dominio disabilitato [Dominio:" + versamentoModel.getUo(this).getDominio(this).getCodDominio() + "].", EsitoOperazione.DOM_001, versamentoModel.getUo(this).getDominio(this).getCodDominio()); } versamenti.add(versamentoModel); } Anagrafica versanteModel = VersamentoUtils.toAnagraficaModel(dto.getVersante()); boolean aggiornaSeEsiste = dto.getAggiornaSeEsisteB() != null ? dto.getAggiornaSeEsisteB() : true; List<Rpt> rpts = avviaTransazione(versamenti, dto.getPortale(), dto.getCanale(), dto.getIbanAddebito(), versanteModel, dto.getAutenticazione(), dto.getUrlRitorno(), aggiornaSeEsiste); AvviaTransazioneDTOResponse response = new AvviaTransazioneDTOResponse(); response.setCodSessione(rpts.get(0).getCodSessione()); response.setPspRedirectURL(rpts.get(0).getPspRedirectURL()); for (Rpt rpt : rpts) { RifTransazione rifTransazione = response.new RifTransazione(); rifTransazione.setCcp(rpt.getCcp()); rifTransazione.setCodApplicazione(rpt.getVersamento(this).getApplicazione(this).getCodApplicazione()); rifTransazione.setCodDominio(rpt.getCodDominio()); rifTransazione.setCodVersamentoEnte(rpt.getVersamento(this).getCodVersamentoEnte()); rifTransazione.setIuv(rpt.getIuv()); response.getRifTransazioni().add(rifTransazione); } return response; }
From source file:org.apache.taverna.scufl2.translator.t2flow.T2FlowParser.java
public void parseAnnotations(WorkflowBean annotatedBean, Annotations annotations) throws ReaderException { // logger.fine("Checking annotations for " + annotatedSubject); Map<String, NetSfTavernaT2AnnotationAnnotationAssertionImpl> annotationElems = new HashMap<>(); if (annotations == null || annotations.getAnnotationChainOrAnnotationChain22() == null) return;/*from w ww. jav a 2 s .c om*/ for (JAXBElement<AnnotationChain> el : annotations.getAnnotationChainOrAnnotationChain22()) { NetSfTavernaT2AnnotationAnnotationAssertionImpl ann = el.getValue() .getNetSfTavernaT2AnnotationAnnotationChainImpl().getAnnotationAssertions() .getNetSfTavernaT2AnnotationAnnotationAssertionImpl(); String annClass = ann.getAnnotationBean().getClazz(); if (annotationElems.containsKey(annClass) && annotationElems.get(annClass).getDate().compareToIgnoreCase(ann.getDate()) > 0) // ann.getDate() is less than current 'latest' annotation, skip continue; annotationElems.put(annClass, ann); } for (String clazz : annotationElems.keySet()) { NetSfTavernaT2AnnotationAnnotationAssertionImpl ann = annotationElems.get(clazz); Calendar cal = parseDate(ann.getDate()); String value = null; String semanticMediaType = TEXT_TURTLE; for (Object obj : ann.getAnnotationBean().getAny()) { if (!(obj instanceof Element)) continue; Element elem = (Element) obj; if (!(elem.getNamespaceURI() == null)) continue; if (elem.getLocalName().equals("text")) { value = elem.getTextContent().trim(); break; } if (clazz.equals(SEMANTIC_ANNOTATION)) { if (elem.getLocalName().equals("content")) value = elem.getTextContent().trim(); if (elem.getLocalName().equals("mimeType")) semanticMediaType = elem.getTextContent().trim(); } } if (value != null) { // Add the annotation Annotation annotation = new Annotation(); WorkflowBundle workflowBundle = parserState.get().getCurrentWorkflowBundle(); annotation.setParent(workflowBundle); String path = "annotation/" + annotation.getName() + ".ttl"; URI bodyURI = URI.create(path); annotation.setTarget(annotatedBean); annotation.setAnnotatedAt(cal); // annotation.setAnnotator(); annotation.setSerializedBy(t2flowParserURI); annotation.setSerializedAt(new GregorianCalendar()); URI annotatedSubject = uriTools.relativeUriForBean(annotatedBean, annotation); String body; if (clazz.equals(SEMANTIC_ANNOTATION)) { String baseStr = "@base <" + annotatedSubject.toASCIIString() + "> .\n"; body = baseStr + value; } else { // Generate Turtle from 'classic' annotation URI predicate = getPredicatesForClass().get(clazz); if (predicate == null) { if (isStrict()) throw new ReaderException("Unsupported annotation class " + clazz); return; } StringBuilder turtle = new StringBuilder(); turtle.append("<"); turtle.append(annotatedSubject.toASCIIString()); turtle.append("> "); turtle.append("<"); turtle.append(predicate.toASCIIString()); turtle.append("> "); // A potentially multi-line string turtle.append("\"\"\""); // Escape existing \ to \\ String escaped = value.replace("\\", "\\\\"); // Escape existing " to \" (beware Java's escaping of \ and " below) escaped = escaped.replace("\"", "\\\""); turtle.append(escaped); turtle.append("\"\"\""); turtle.append(" ."); body = turtle.toString(); } try { workflowBundle.getResources().addResource(body, path, semanticMediaType); } catch (IOException e) { throw new ReaderException("Could not store annotation body to " + path, e); } annotation.setBody(bodyURI); } } }
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
public String loadPreviousQueries(boolean getAllInGroup) { System.out.println("Loading previous queries for: " + System.getProperty("user")); String xmlStr = writeContentQueryXML(getAllInGroup); lastRequestMessage = xmlStr;/*from w w w. ja v a 2s . c o m*/ //System.out.println(xmlStr); String responseStr = QueryListNamesClient.sendQueryRequestREST(xmlStr); if (responseStr.equalsIgnoreCase("CellDown")) { cellStatus = new String("CellDown"); return "CellDown"; } lastResponseMessage = responseStr; try { JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass( bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class); previousQueries = new ArrayList<QueryMasterData>(); for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) { QueryMasterData tmpData; tmpData = new QueryMasterData(); XMLGregorianCalendar cldr = queryMasterType.getCreateDate(); tmpData.name( queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]"); tmpData.tooltip("A query run by " + queryMasterType.getUserId());//System.getProperty("user")); tmpData.visualAttribute("CA"); tmpData.xmlContent(null); tmpData.id(new Integer(queryMasterType.getQueryMasterId()).toString()); tmpData.userId(queryMasterType.getUserId()); //System.getProperty("user")); previousQueries.add(tmpData); } return ""; } catch (Exception e) { e.printStackTrace(); return "error"; } }
From source file:com.evolveum.midpoint.prism.util.JaxbTestUtil.java
public <T> T unmarshalObject(Object domOrJaxbElement, Class<T> type) throws SchemaException { JAXBElement<T> element; if (domOrJaxbElement instanceof JAXBElement<?>) { element = (JAXBElement<T>) domOrJaxbElement; } else if (domOrJaxbElement instanceof Node) { try {//from ww w.j a v a2 s. c o m element = unmarshalElement((Node) domOrJaxbElement, type); } catch (JAXBException e) { throw new SchemaException(e.getMessage(), e); } } else { throw new IllegalArgumentException("Unknown element type " + domOrJaxbElement); } if (element == null) { return null; } T value = element.getValue(); adopt(value, type); return value; }
From source file:edu.harvard.i2b2.analysis.ui.AnalysisComposite.java
@SuppressWarnings("unchecked") public void insertNodes(final QueryInstanceData data) { // QueryInstanceData data = (QueryInstanceData) node.getUserObject(); getDisplay().syncExec(new Runnable() { public void run() { // tree1.select(tree1.getItem(index).getItem(index)); queryName = "Query Name: " + data.name(); label1.setText("Query Name: " + data.name()); JFreeChart chart = createWaitingChart(createEmptyDataset()); ChartComposite frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true);/*from w ww . jav a2 s . com*/ composite1.getChildren()[0].dispose(); frame.pack(); composite1.layout(); getDisplay().update(); } }); try { addParentNode(data); String xmlRequest = data.writeContentQueryXML(); String xmlResponse = null; if (System.getProperty("webServiceMethod").equals("SOAP")) { xmlResponse = QueryClient.sendQueryRequestSOAP(xmlRequest); } else { xmlResponse = QueryClient.sendQueryRequestREST(xmlRequest); } if (xmlResponse.equalsIgnoreCase("CellDown")) { return; } JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), ResultResponseType.class); for (QueryResultInstanceType queryResultInstanceType : resultResponseType.getQueryResultInstance()) { @SuppressWarnings("unused") String status = queryResultInstanceType.getQueryStatusType().getName(); QueryResultData resultData = new QueryResultData(); if (queryResultInstanceType.getQueryResultType().getName().equalsIgnoreCase("PATIENTSET")) { resultData.visualAttribute("FA"); } else { resultData.visualAttribute("LAO"); } // resultData.queryId(data.queryId()); resultData.patientRefId(queryResultInstanceType.getResultInstanceId());// data.patientRefId()); resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());// data.patientCount()); String resultname = ""; if ((resultname = queryResultInstanceType.getDescription()) == null) { resultname = queryResultInstanceType.getQueryResultType().getDescription(); } // if (status.equalsIgnoreCase("FINISHED")) { if ((!queryResultInstanceType.getQueryResultType().getDisplayType() .equalsIgnoreCase("CATNUM")) /* * || * queryResultInstanceType * . * getQueryResultType * (). * getResultTypeId * (). * equalsIgnoreCase * ("4") */) { continue; } resultData.name(resultname);// + " - " // + resultData.patientCount() + " Patients"); resultData.tooltip(resultData.patientCount() + " Patients"); // } else { // resultData.name(resultname);// + " - " + status); // resultData.tooltip(status); // } resultData.xmlContent(xmlResponse); resultData.queryName(data.queryName()); resultData.type(queryResultInstanceType.getQueryResultType().getName()); resultData.queryId(queryResultInstanceType.getResultInstanceId()); addNode(resultData); } // jTree1.scrollPathToVisible(new TreePath(node.getPath())); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.harvard.i2b2.analysis.ui.AnalysisComposite.java
public void setSelection(final int index) { getDisplay().syncExec(new Runnable() { @SuppressWarnings("unchecked") public void run() { tree1.select(tree1.getItem(index).getItem(0)); JFreeChart chart = createWaitingChart(createEmptyDataset()); ChartComposite frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true);/* w w w. ja va 2s . c o m*/ composite1.getChildren()[0].dispose(); frame.pack(); composite1.layout(); getDisplay().update(); QueryResultData resultData = (QueryResultData) tree1.getItem(index).getItem(0).getData(); String xmlDocumentRequestStr = resultData.writeXMLDocumentQueryXML(); log.debug("Generated Age XML document request: " + xmlDocumentRequestStr); String response = QueryClient.sendQueryRequestREST(xmlDocumentRequestStr); log.debug("Age XML document response: " + response); boolean celldown = false; if (response.equalsIgnoreCase("CellDown")) { // cellStatus = new String("CellDown"); celldown = true; chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); return; } try { JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); CrcXmlResultResponseType resultResponseType = (CrcXmlResultResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), CrcXmlResultResponseType.class); for (Condition status : resultResponseType.getStatus().getCondition()) { if (status.getType().equals("ERROR")) { // cellStatus = new String("CellDown"); chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); return; } } String xmlString = (String) resultResponseType.getCrcXmlResult().getXmlValue().getContent() .get(0); jaxbElement = jaxbUtil.unMashallFromString(xmlString); ResultEnvelopeType resultEnvelopeType1 = (ResultEnvelopeType) jaxbElement.getValue(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); ResultType umResultType = (ResultType) helper .getObjectByClass(resultEnvelopeType1.getBody().getAny(), ResultType.class); String description = ""; if ((description = resultResponseType.getQueryResultInstance().getDescription()) == null) { description = resultResponseType.getQueryResultInstance().getQueryResultType() .getDescription(); } // if // (UserInfoBean.getInstance().isRoleInProject("DATA_OBFSC" // )) // { // description+=""; // } chart = createChart(createDataset(umResultType, description), description); // final ChartPanel chartPanel = new ChartPanel(chart); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); } catch (Exception e) { e.printStackTrace(); chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); return; } } }); }
From source file:edu.harvard.i2b2.analysis.ui.AnalysisComposite.java
public void setSelection(final QueryResultData resultData) { getDisplay().syncExec(new Runnable() { @SuppressWarnings("unchecked") public void run() { JFreeChart chart = createWaitingChart(createEmptyDataset()); ChartComposite frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true);/*from w ww . ja v a 2 s .c om*/ composite1.getChildren()[0].dispose(); frame.pack(); composite1.layout(); getDisplay().update(); // tree1.select(tree1.getItem(index).getItem(index)); // QueryResultData resultData = // (QueryResultData)tree1.getItem(0).getItem(0).getData(); String xmlDocumentRequestStr = resultData.writeXMLDocumentQueryXML(); log.debug("Generated Age XML document request: " + xmlDocumentRequestStr); // parentPanel.lastRequestMessage( // xmlDocumentRequestStr); String response = QueryClient.sendQueryRequestREST(xmlDocumentRequestStr); log.debug("Age XML document response: " + response); boolean celldown = false; if (response.equalsIgnoreCase("CellDown")) { // cellStatus = new String("CellDown"); celldown = true; chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); return; } try { JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); CrcXmlResultResponseType resultResponseType = (CrcXmlResultResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), CrcXmlResultResponseType.class); for (Condition status : resultResponseType.getStatus().getCondition()) { if (status.getType().equals("ERROR")) { // cellStatus = new String("CellDown"); chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); return; } } String xmlString = (String) resultResponseType.getCrcXmlResult().getXmlValue().getContent() .get(0); jaxbElement = jaxbUtil.unMashallFromString(xmlString); ResultEnvelopeType resultEnvelopeType1 = (ResultEnvelopeType) jaxbElement.getValue(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); ResultType umResultType = (ResultType) helper .getObjectByClass(resultEnvelopeType1.getBody().getAny(), ResultType.class); String description = ""; if ((description = resultResponseType.getQueryResultInstance().getDescription()) == null) { description = resultResponseType.getQueryResultInstance().getQueryResultType() .getDescription(); } // if // (UserInfoBean.getInstance().isRoleInProject("DATA_OBFSC" // )) // { // description+=""; // } chart = createChart(createDataset(umResultType, description), description); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); } catch (Exception e) { e.printStackTrace(); chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); return; } } }); }
From source file:com.t2tierp.controller.nfe.NfeCabecalhoController.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public void cancelaNfe() { if (certificado == null || certificado.getArquivo() == null || certificado.getSenha() == null) { FacesContextUtil.adiconaMensagem(FacesMessage.SEVERITY_INFO, " Necessrio informar os dados do certificado antes do cancelamento!", null); } else {//from w w w . ja va 2 s . c o m try { if (justificativaCancelamento == null) { throw new Exception(" necessrio informar uma justificativa para o cancelamento da NF-e."); } if (justificativaCancelamento.trim().equals("")) { throw new Exception(" necessrio informar uma justificativa para o cancelamento da NF-e."); } if (justificativaCancelamento.trim().length() < 15) { throw new Exception("A justificativa deve ter no mnimo 15 caracteres."); } if (justificativaCancelamento.trim().length() > 255) { throw new Exception("A justificativa deve ter no mximo 255 caracteres."); } if (getObjeto().getStatusNota().intValue() == 6) { throw new Exception("NF-e j cancelada. Cancelamento no permitido!"); } if (getObjeto().getStatusNota().intValue() != 5) { throw new Exception("NF-e no autorizada. Cancelamento no permitido!"); } ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); String caminhoArquivo = context.getRealPath(diretorioXml) + System.getProperty("file.separator") + getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso() + "-nfeproc.xml"; File arquivoXml = new File(caminhoArquivo); if (!arquivoXml.exists()) { throw new Exception("Arquivo XML da NF-e no localizado!"); } JAXBContext jc = JAXBContext.newInstance("br.inf.portalfiscal.nfe.procnfe"); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement<TNfeProc> element = (JAXBElement) unmarshaller.unmarshal(arquivoXml); String protocolo = element.getValue().getProtNFe().getInfProt().getNProt(); getKeyStore(); CancelaNfe cancelaNfe = new CancelaNfe(); Map dadosCancelamento = cancelaNfe.cancelaNfe(certificado.getAlias(), getKeyStore(), certificado.getSenha(), getObjeto().getUfEmitente().toString(), String.valueOf(getObjeto().getAmbiente()), getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso(), protocolo, justificativaCancelamento.trim(), getObjeto().getEmpresa().getCnpj()); RespostaSefaz respostaSefaz = new RespostaSefaz(); respostaSefaz.setCancelado((Boolean) dadosCancelamento.get("nfeCancelada")); String resposta = ""; if (respostaSefaz.isCancelado()) { // salva o xml caminhoArquivo = context.getRealPath(diretorioXml) + System.getProperty("file.separator") + getObjeto().getChaveAcesso() + getObjeto().getDigitoChaveAcesso() + "-nfeCanc.xml"; OutputStream out = new FileOutputStream(new File(caminhoArquivo)); out.write(((String) dadosCancelamento.get("xmlCancelamento")).getBytes()); out.close(); getObjeto().setStatusNota(6); setObjeto(dao.merge(getObjeto())); // atualiza o estoque for (NfeDetalhe nfeDetalhe : getObjeto().getListaNfeDetalhe()) { controleEstoqueDao.atualizaEstoque(nfeDetalhe.getProduto().getId(), nfeDetalhe.getQuantidadeComercial()); } resposta += "NF-e Cancelada com sucesso"; } else { resposta += "A NF-e NO foi cancelada."; } resposta += "\n" + (String) dadosCancelamento.get("motivo1"); resposta += "\n" + (String) dadosCancelamento.get("motivo2"); respostaSefaz.setResposta(resposta); FacesContextUtil.adiconaMensagem(FacesMessage.SEVERITY_INFO, respostaSefaz.getResposta(), ""); } catch (Exception e) { e.printStackTrace(); FacesContextUtil.adiconaMensagem(FacesMessage.SEVERITY_ERROR, "Ocorreu um erro ao cancelar a NF-e!", e.getMessage()); } } }