List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:org.entrystore.repository.impl.EntryImpl.java
private void initialize(GraphType bt, EntryType locT, ResourceType repT, RepositoryConnection rc) throws RepositoryException, DatatypeConfigurationException { ValueFactory vf = rc.getRepository().getValueFactory(); if (bt != null) { setBuiltinType(bt, rc);// ww w . j a v a 2s . co m } if (repT != null && resourceType == GraphType.None) { setRepresentationType(repT, rc); } setLocationType(locT, rc); rc.add(entryURI, RepositoryProperties.resource, this.resURI, entryURI); created = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); rc.add(entryURI, RepositoryProperties.Created, vf.createLiteral(created), entryURI); registerEntryModified(rc, vf); /* * Adds a statement with the entry URI as subject, * relation as predicate, and the relation URI as * an object to the scam repository, the named context is the entry. */ rc.add(entryURI, RepositoryProperties.relation, this.relationURI, entryURI); if (locT != EntryType.Reference) { rc.add(entryURI, RepositoryProperties.metadata, this.localMdURI, entryURI); } if (locT == EntryType.Reference || locT == EntryType.LinkReference) { rc.add(entryURI, RepositoryProperties.externalMetadata, this.externalMdURI, entryURI); rc.add(entryURI, RepositoryProperties.cachedExternalMetadata, this.cachedExternalMdURI, entryURI); } if (!this.id.startsWith("_")) { //System entries don't have creators, because they're created by the system. PrincipalManager pm = this.repositoryManager.getPrincipalManager(); if (pm != null) { java.net.URI userURI = pm.getAuthenticatedUserURI(); if (userURI != null) { this.creator = vf.createURI(userURI.toString()); rc.add(entryURI, RepositoryProperties.Creator, this.creator, entryURI); } } } //referredIn = new HashSet<java.net.URI>(); //TODO Check so that not a Context is a NamedResource and other restrictions. }
From source file:org.entrystore.repository.impl.EntryImpl.java
protected void registerEntryModified(RepositoryConnection rc, ValueFactory vf) throws RepositoryException { try {/*from ww w .j av a2 s. co m*/ modified = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); } catch (DatatypeConfigurationException e) { log.error(e.getMessage()); throw new RepositoryException(e.getMessage(), e); } rc.remove(rc.getStatements(entryURI, RepositoryProperties.Modified, null, false, entryURI), entryURI); rc.add(entryURI, RepositoryProperties.Modified, vf.createLiteral(modified), entryURI); //Also adding the one who update using dcterms:contributor if (this.repositoryManager != null && this.repositoryManager.getPrincipalManager() != null && this.repositoryManager.getPrincipalManager().getAuthenticatedUserURI() != null) { java.net.URI contrib = this.repositoryManager.getPrincipalManager().getAuthenticatedUserURI(); String contributor = contrib.toString(); URI contributorURI = vf.createURI(contributor); //Do not add if the contributor is the same as the creator if (contrib != null && !contrib.equals(this.getCreator()) && contributors != null && !contributors.contains(contributorURI)) { rc.add(this.entryURI, RepositoryProperties.Contributor, contributorURI, this.entryURI); contributors.add(contributorURI); } } }
From source file:org.entrystore.repository.impl.EntryImpl.java
public void updateCachedExternalMetadataDateSynchronized(RepositoryConnection rc, ValueFactory vf) throws RepositoryException, DatatypeConfigurationException { synchronized (this.repository) { if (this.getEntryType() == EntryType.Reference || this.getEntryType() == EntryType.LinkReference) { cachedAt = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); rc.remove(rc.getStatements(cachedExternalMdURI, RepositoryProperties.cached, null, false, entryURI), entryURI);/*from w w w . j a va2s. c om*/ // TODO: maybe entryUri as context last parameter.. rc.add(cachedExternalMdURI, RepositoryProperties.cached, vf.createLiteral(cachedAt), entryURI); } registerEntryModified(rc, vf); } }
From source file:org.entrystore.repository.impl.EntryImpl.java
public void setGraph(Graph metametadata) { checkAdministerRights();/*from ww w.j a v a 2 s . co m*/ Iterator<Statement> resourceURIStmnts = metametadata.match(this.entryURI, RepositoryProperties.resource, null); if (resourceURIStmnts.hasNext()) { Value newResourceURI = resourceURIStmnts.next().getObject(); if (newResourceURI instanceof URI) { setResourceURI(java.net.URI.create(newResourceURI.toString())); } } Iterator<Statement> externalMdURIStmnts = metametadata.match(this.entryURI, RepositoryProperties.externalMetadata, null); if (externalMdURIStmnts.hasNext()) { Value newResourceURI = externalMdURIStmnts.next().getObject(); if (newResourceURI instanceof URI) { setExternalMetadataURI(java.net.URI.create(newResourceURI.toString())); } } String originalList = this.getOriginalList(); try { synchronized (this.repository) { ValueFactory vf = this.repository.getValueFactory(); RepositoryConnection rc = this.repository.getConnection(); rc.setAutoCommit(false); try { rc.clear(entryURI); for (Statement statement : metametadata) { URI predicate = statement.getPredicate(); if (predicate.stringValue().startsWith(RepositoryProperties.NSbase)) { //Ignore basic structure subgraph, will be added below. if (!(predicate.equals(RepositoryProperties.resource) || predicate.equals(RepositoryProperties.metadata) || predicate.equals(RepositoryProperties.externalMetadata) || predicate.equals(RepositoryProperties.cachedExternalMetadata) || predicate.equals(RepositoryProperties.cached) || predicate.equals(RepositoryProperties.relation) //|| predicate.equals(RepositoryProperties.referredIn) )) { rc.add(statement, entryURI); } } else if (this.entryURI.equals(statement.getSubject()) && (predicate.equals(RepositoryProperties.Created) || predicate.equals(RepositoryProperties.Modified) || predicate.equals(RepositoryProperties.Creator) || predicate.equals(RepositoryProperties.Contributor))) { //In basic structure below. } else if (predicate.equals(RDF.TYPE)) { if (this.entryURI.equals(statement.getSubject())) { EntryType lt = getLocationType(statement.getObject()); if (lt != null && locType == EntryType.Reference && lt == EntryType.LinkReference) { //Only allowed to change from Reference to LinkReference locType = lt; localMdURI = vf .createURI(URISplit .fabricateURI(repositoryManager.getRepositoryURL().toString(), context.id, RepositoryProperties.MD_PATH, this.id) .toString()); } } else { GraphType bt = getBuiltinType(statement.getObject()); if (bt != null) { if (locType != EntryType.Local) { //Only allowed to change builtintype for non local resources. this.resourceType = bt; } } else { ResourceType rt = getRepresentationType(statement.getObject()); if (rt != null) { if (locType != EntryType.Local) { //Only allowed to change representationtype for non local resources. repType = rt; } } else { //Some other rdf:type, just add it. rc.add(statement, entryURI); } } } } else { rc.add(statement, entryURI); } } //----------Start basic structure: //Since we cleared the previous graph, we set the types again, they might have been updated in the loop above. setLocationType(this.locType, rc); setBuiltinType(this.resourceType, rc); setRepresentationType(this.repType, rc); rc.add(entryURI, RepositoryProperties.resource, getSesameResourceURI(), entryURI); rc.add(entryURI, RepositoryProperties.relation, getSesameRelationURI(), entryURI); if (localMdURI != null) { rc.add(entryURI, RepositoryProperties.metadata, localMdURI, entryURI); } if (externalMdURI != null) { rc.add(entryURI, RepositoryProperties.externalMetadata, externalMdURI, entryURI); } if (cachedExternalMdURI != null) { rc.add(entryURI, RepositoryProperties.cachedExternalMetadata, cachedExternalMdURI, entryURI); if (cachedAt != null) { rc.add(cachedExternalMdURI, RepositoryProperties.cached, vf.createLiteral(cachedAt), entryURI); } } /* for (java.net.URI refIn : this.referredIn) { //Adds the referredIn relations to the graph. rc.add(entryURI, RepositoryProperties.referredIn, vf.createURI(refIn.toString()), entryURI); }*/ if (created != null) { rc.add(entryURI, RepositoryProperties.Created, vf.createLiteral(created), entryURI); } if (creator != null) { rc.add(entryURI, RepositoryProperties.Creator, creator, entryURI); } if (contributors != null && contributors.size() > 0) { for (Iterator<URI> iter = contributors.iterator(); iter.hasNext();) { URI contrib = iter.next(); rc.add(entryURI, RepositoryProperties.Contributor, contrib, entryURI); } } if (originalList != null) { rc.add(entryURI, RepositoryProperties.originallyCreatedIn, vf.createURI(originalList), entryURI); } modified = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); rc.add(entryURI, RepositoryProperties.Modified, vf.createLiteral(modified), entryURI); //------------End basic structure rc.commit(); administerPrincipals = null; readMetadataPrincipals = null; writeMetadataPrincipals = null; readResourcePrincipals = null; writeResourcePrincipals = null; readOrWrite = null; format = null; // we reload the internal cache loadFromStatements(rc.getStatements(null, null, null, false, entryURI).asList()); initMetadataObjects(); getRepositoryManager() .fireRepositoryEvent(new RepositoryEventObject(this, RepositoryEvent.EntryUpdated)); } catch (Exception e) { rc.rollback(); // Reset to previous saved values, just in case we saved the types above halfway through. loadFromStatements(rc.getStatements(null, null, null, false, entryURI).asList()); e.printStackTrace(); throw new org.entrystore.repository.RepositoryException("Error in repository connection.", e); } finally { rc.close(); } } } catch (RepositoryException e) { e.printStackTrace(); throw new org.entrystore.repository.RepositoryException("Failed to connect to Repository.", e); } }
From source file:org.fcrepo.oai.service.OAIProviderService.java
public OAIProviderService() throws DatatypeConfigurationException, JAXBException { this.dataFactory = DatatypeFactory.newInstance(); this.unmarshaller = JAXBContext.newInstance(OAIPMHtype.class, IdentifyType.class, SetType.class) .createUnmarshaller();/* w w w. ja v a2s . co m*/ }
From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java
private Payment convertToSAFTPaymentDocument(SettlementNote document, Map<String, oecd.standardauditfile_tax.pt_1.Customer> baseCustomers, Map<String, oecd.standardauditfile_tax.pt_1.Product> productMap) { Payment payment = new Payment(); // Find the Customer in BaseCustomers oecd.standardauditfile_tax.pt_1.Customer customer = null; if (baseCustomers.containsKey(document.getDebtAccount().getCustomer().getCode())) { customer = baseCustomers.get(document.getDebtAccount().getCustomer().getCode()); } else {/*www . j a v a 2 s.c om*/ // If not found, create a new one and add it to baseCustomers customer = convertCustomerToSAFTCustomer(document.getDebtAccount().getCustomer()); baseCustomers.put(customer.getCustomerID(), customer); } // MovementDate DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); DateTime documentDate = document.getDocumentDate(); // SystemEntryDate payment.setSystemEntryDate(convertToXMLDateTime(dataTypeFactory, documentDate)); payment.setTransactionDate(convertToXMLDateTime(dataTypeFactory, documentDate)); // DocumentNumber payment.setPaymentRefNo(document.getUiDocumentNumber()); // CustomerID payment.setCustomerID(document.getDebtAccount().getCustomer().getCode()); // DocumentStatus /* * Deve ser preenchido com: ?N? ? Normal; Texto 1 ?T? ? Por conta de * terceiros; ?A? ? Documento anulado. */ SourceDocuments.Payments.Payment.DocumentStatus status = new SourceDocuments.Payments.Payment.DocumentStatus(); if (document.isAnnulled()) { status.setPaymentStatus("A"); } else { status.setPaymentStatus("N"); } status.setPaymentStatusDate(payment.getSystemEntryDate()); // status.setReason(""); // Utilizador responsvel pelo estado atual do docu-mento. status.setSourceID(document.getVersioningUpdatedBy()); // Deve ser preenchido com: // 'P' - Documento produzido na aplicacao; if (Boolean.TRUE.equals(document.getDocumentNumberSeries().getSeries().getExternSeries()) || Boolean.TRUE.equals(document.getDocumentNumberSeries().getSeries().getLegacy())) { status.setSourcePayment(SAFTPTSourcePayment.I); } else { status.setSourcePayment(SAFTPTSourcePayment.P); } payment.setDocumentStatus(status); //Check if is Rehimbursement/Payment if (Constants.isPositive(document.getTotalPayedAmount())) { //PaymentMethods for (PaymentEntry paymentEntry : document.getPaymentEntriesSet()) { PaymentMethod method = new PaymentMethod(); method.setPaymentAmount(paymentEntry.getPayedAmount().setScale(2, RoundingMode.HALF_EVEN)); method.setPaymentDate(payment.getTransactionDate()); method.setPaymentMechanism(convertToSAFTPaymentMechanism(paymentEntry.getPaymentMethod())); payment.getPaymentMethod().add(method); } payment.setSettlementType(SAFTPTSettlementType.NL); } else if (Constants.isPositive(document.getTotalReimbursementAmount())) { //Reimbursments for (ReimbursementEntry reimbursmentEntry : document.getReimbursementEntriesSet()) { PaymentMethod method = new PaymentMethod(); method.setPaymentAmount( reimbursmentEntry.getReimbursedAmount().setScale(2, RoundingMode.HALF_EVEN)); method.setPaymentDate(payment.getTransactionDate()); method.setPaymentMechanism(convertToSAFTPaymentMechanism(reimbursmentEntry.getPaymentMethod())); payment.getPaymentMethod().add(method); payment.setSettlementType(SAFTPTSettlementType.NR); } } else { payment.setSettlementType(SAFTPTSettlementType.NN); } payment.setSourceID(document.getVersioningCreator()); // DocumentTotals SourceDocuments.Payments.Payment.DocumentTotals docTotals = new SourceDocuments.Payments.Payment.DocumentTotals(); //Lines BigInteger i = BigInteger.ONE; for (SettlementEntry settlementEntry : document.getSettlemetEntriesSet()) { SourceDocuments.Payments.Payment.Line line = new SourceDocuments.Payments.Payment.Line(); line.setLineNumber(i); //SourceDocument SourceDocumentID sourceDocument = new SourceDocumentID(); sourceDocument.setLineNumber(BigInteger.valueOf(settlementEntry.getInvoiceEntry().getEntryOrder())); sourceDocument.setOriginatingON( settlementEntry.getInvoiceEntry().getFinantialDocument().getUiDocumentNumber()); sourceDocument.setInvoiceDate(convertToXMLDateTime(dataTypeFactory, settlementEntry.getInvoiceEntry().getFinantialDocument().getDocumentDate())); sourceDocument.setDescription(settlementEntry.getDescription()); line.getSourceDocumentID().add(sourceDocument); //SettlementAmount line.setSettlementAmount(BigDecimal.ZERO); if (settlementEntry.getInvoiceEntry().isDebitNoteEntry()) { line.setDebitAmount(settlementEntry.getTotalAmount()); } else if (settlementEntry.getInvoiceEntry().isCreditNoteEntry()) { line.setCreditAmount(settlementEntry.getTotalAmount()); } payment.getLine().add(line); i = i.add(BigInteger.ONE); } docTotals.setGrossTotal(document.getTotalAmount().setScale(2, RoundingMode.HALF_EVEN)); docTotals.setNetTotal(document.getTotalAmount().setScale(2, RoundingMode.HALF_EVEN)); docTotals.setTaxPayable(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_EVEN)); payment.setDocumentTotals(docTotals); // Period /* * Per?odo contabil?stico (Period) . . . . . . . . . . Deve ser * indicado o n?mero do m?s do per?odo de tributa??o, de ?1? a ?12?, * contado desde a data do in?cio. Pode ainda ser preenchido com * ?13?, ?14?, ?15? ou ?16? para movimentos efectuados no ?ltimo m?s * do per?odo de tributa??o, relacionados com o apuramento do * resultado. Ex.: movimentos de apuramentos de invent?rios, * deprecia??es, ajustamentos ou apuramentos de resultados. */ payment.setPeriod(document.getDocumentDate().getMonthOfYear()); // SourceID /* * C?digo do utilizador que registou o movimento (SourceID). */ payment.setSourceID(document.getVersioningCreator()); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return payment; }
From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java
private WorkDocument convertToSAFTWorkDocument(Invoice document, Map<String, oecd.standardauditfile_tax.pt_1.Customer> baseCustomers, Map<String, oecd.standardauditfile_tax.pt_1.Product> baseProducts) { WorkDocument workDocument = new WorkDocument(); // Find the Customer in BaseCustomers oecd.standardauditfile_tax.pt_1.Customer customer = null; if (baseCustomers.containsKey(document.getDebtAccount().getCustomer().getCode())) { customer = baseCustomers.get(document.getDebtAccount().getCustomer().getCode()); } else {/*from ww w. ja v a2s. c om*/ // If not found, create a new one and add it to baseCustomers customer = convertCustomerToSAFTCustomer(document.getDebtAccount().getCustomer()); baseCustomers.put(customer.getCustomerID(), customer); } //check the PayorDebtAccount if (document.getPayorDebtAccount() != null) { if (baseCustomers.containsKey(document.getPayorDebtAccount().getCustomer().getCode())) { //do nothing } else { // If not found, create a new one and add it to baseCustomers oecd.standardauditfile_tax.pt_1.Customer payorCustomer = convertCustomerToSAFTCustomer( document.getPayorDebtAccount().getCustomer()); baseCustomers.put(payorCustomer.getCustomerID(), payorCustomer); } } // MovementDate DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); DateTime documentDate = document.getDocumentDate(); // SystemEntryDate workDocument.setSystemEntryDate(convertToXMLDateTime(dataTypeFactory, documentDate)); workDocument.setWorkDate(convertToXMLDateTime(dataTypeFactory, documentDate)); // DocumentNumber workDocument.setDocumentNumber(document.getUiDocumentNumber()); // CustomerID workDocument.setCustomerID(document.getDebtAccount().getCustomer().getCode()); //PayorID if (document.getPayorDebtAccount() != null) { workDocument.setPayorCustomerID(document.getPayorDebtAccount().getCustomer().getCode()); } // DocumentStatus /* * Deve ser preenchido com: ?N? ? Normal; Texto 1 ?T? ? Por conta de * terceiros; ?A? ? Documento anulado. */ SourceDocuments.WorkingDocuments.WorkDocument.DocumentStatus status = new SourceDocuments.WorkingDocuments.WorkDocument.DocumentStatus(); if (document.isAnnulled()) { status.setWorkStatus("A"); } else { status.setWorkStatus("N"); } status.setWorkStatusDate(workDocument.getSystemEntryDate()); // status.setReason(""); // Utilizador responsvel pelo estado atual do docu-mento. status.setSourceID(document.getVersioningUpdatedBy()); // Deve ser preenchido com: // 'P' - Documento produzido na aplicacao; if (Boolean.TRUE.equals(document.getDocumentNumberSeries().getSeries().getExternSeries())) { status.setSourceBilling(SAFTPTSourceBilling.I); } else { status.setSourceBilling(SAFTPTSourceBilling.P); } workDocument.setDocumentStatus(status); // DocumentTotals SourceDocuments.WorkingDocuments.WorkDocument.DocumentTotals docTotals = new SourceDocuments.WorkingDocuments.WorkDocument.DocumentTotals(); docTotals.setGrossTotal(document.getTotalAmount().setScale(2, RoundingMode.HALF_EVEN)); docTotals.setNetTotal(document.getTotalNetAmount().setScale(2, RoundingMode.HALF_EVEN)); docTotals.setTaxPayable(document.getTotalAmount().subtract(document.getTotalNetAmount()).setScale(2, RoundingMode.HALF_EVEN)); workDocument.setDocumentTotals(docTotals); // WorkType /* * Deve ser preenchido com: Texto 2 "DC" Documentos emitidos que * sejam suscetiveis de apresentacao ao cliente para conferencia de * entrega de mercadorias ou da prestacao de servicos. "FC" Fatura * de consignacao nos termos do artigo 38 do codigo do IVA. */ workDocument.setWorkType("DC"); // Period /* * Per?odo contabil?stico (Period) . . . . . . . . . . Deve ser * indicado o n?mero do m?s do per?odo de tributa??o, de ?1? a ?12?, * contado desde a data do in?cio. Pode ainda ser preenchido com * ?13?, ?14?, ?15? ou ?16? para movimentos efectuados no ?ltimo m?s * do per?odo de tributa??o, relacionados com o apuramento do * resultado. Ex.: movimentos de apuramentos de invent?rios, * deprecia??es, ajustamentos ou apuramentos de resultados. */ workDocument.setPeriod(document.getDocumentDate().getMonthOfYear()); // SourceID /* * C?digo do utilizador que registou o movimento (SourceID). */ workDocument.setSourceID(document.getVersioningCreator()); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } List<oecd.standardauditfile_tax.pt_1.SourceDocuments.WorkingDocuments.WorkDocument.Line> productLines = workDocument .getLine(); // Process individual BigInteger i = BigInteger.ONE; for (FinantialDocumentEntry docLine : document.getFinantialDocumentEntriesSet()) { InvoiceEntry orderNoteLine = (InvoiceEntry) docLine; oecd.standardauditfile_tax.pt_1.SourceDocuments.WorkingDocuments.WorkDocument.Line line = convertToSAFTWorkDocumentLine( orderNoteLine, baseProducts); // LineNumber line.setLineNumber(i); // Add to productLines i = i.add(BigInteger.ONE); productLines.add(line); } return workDocument; }
From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java
private oecd.standardauditfile_tax.pt_1.SourceDocuments.WorkingDocuments.WorkDocument.Line convertToSAFTWorkDocumentLine( InvoiceEntry entry, Map<String, oecd.standardauditfile_tax.pt_1.Product> baseProducts) { oecd.standardauditfile_tax.pt_1.Product currentProduct = null; Product product = entry.getProduct(); if (product.getCode() != null && baseProducts.containsKey(product.getCode())) { currentProduct = baseProducts.get(product.getCode()); } else {/* ww w. j a v a 2 s.c om*/ currentProduct = convertProductToSAFTProduct(product); baseProducts.put(currentProduct.getProductCode(), currentProduct); } XMLGregorianCalendar documentDateCalendar = null; try { DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance(); DateTime documentDate = entry.getFinantialDocument().getDocumentDate(); documentDateCalendar = convertToXMLDateTime(dataTypeFactory, documentDate); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } oecd.standardauditfile_tax.pt_1.SourceDocuments.WorkingDocuments.WorkDocument.Line line = new oecd.standardauditfile_tax.pt_1.SourceDocuments.WorkingDocuments.WorkDocument.Line(); if (entry.isCreditNoteEntry()) { line.setCreditAmount(entry.getAmount().setScale(2, RoundingMode.HALF_EVEN)); } else if (entry.isDebitNoteEntry()) { line.setDebitAmount(entry.getAmount().setScale(2, RoundingMode.HALF_EVEN)); } // Description line.setDescription(entry.getDescription()); List<OrderReferences> orderReferences = line.getOrderReferences(); //Add the references on the document creditEntries <-> debitEntries if (entry.isCreditNoteEntry()) { CreditEntry creditEntry = (CreditEntry) entry; if (creditEntry.getDebitEntry() != null) { OrderReferences reference = new OrderReferences(); reference .setOriginatingON(creditEntry.getDebitEntry().getFinantialDocument().getUiDocumentNumber()); reference.setOrderDate(documentDateCalendar); orderReferences.add(reference); } } else if (entry.isDebitNoteEntry()) { // DebitEntry debitEntry = (DebitEntry) entry; // for (CreditEntry creditEntry : debitEntry.getCreditEntriesSet()) { // OrderReferences reference = new OrderReferences(); // reference.setOriginatingON(creditEntry.getFinantialDocument().getUiDocumentNumber()); // reference.setOrderDate(documentDateCalendar); // orderReferences.add(reference); // } } // ProductCode line.setProductCode(currentProduct.getProductCode()); // ProductDescription line.setProductDescription(currentProduct.getProductDescription()); // Quantity line.setQuantity(entry.getQuantity()); // SettlementAmount line.setSettlementAmount(BigDecimal.ZERO); // Tax line.setTax(getSAFTWorkingDocumentsTax(product, entry.getVat())); line.setTaxPointDate(documentDateCalendar); // TaxExemptionReason /* * Motivo da isen??o de imposto (TaxExemptionReason). Campo de * preenchimento obrigat?rio, quando os campos percentagem da taxa de * imposto (TaxPercentage) ou montante do imposto (TaxAmount) s?o iguais * a zero. Deve ser referido o preceito legal aplic?vel. . . . . . . . . * . Texto 60 */ if (line.getTax().getTaxPercentage() == BigDecimal.ZERO) { Vat vat = entry.getVat(); if (vat.getVatExemptionReason() != null) { line.setTaxExemptionReason( vat.getVatExemptionReason().getCode() + "-" + vat.getVatExemptionReason().getName()); } else { // HACK : DEFAULT // line.setTaxExemptionReason(VatExemptionReason.M1().getCode() // + "-" + VatExemptionReason.M1().getDescription()); } } // UnitOfMeasure line.setUnitOfMeasure(product.getUnitOfMeasure().getContent()); // UnitPrice line.setUnitPrice(entry.getAmount().setScale(2, RoundingMode.HALF_EVEN)); return line; }
From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java
private Header createSAFTHeader(DateTime startDate, DateTime endDate, FinantialInstitution finantialInstitution, String auditVersion) {/* w ww . ja v a2 s. c om*/ Header header = new Header(); DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); // AuditFileVersion header.setAuditFileVersion(auditVersion); // BusinessName - Nome da Empresa header.setBusinessName(finantialInstitution.getCompanyName()); header.setCompanyName(finantialInstitution.getName()); // CompanyAddress AddressStructurePT companyAddress = null; //TODOJN Locale por resolver companyAddress = convertAddressToAddressPT(finantialInstitution.getAddress(), finantialInstitution.getZipCode(), finantialInstitution.getMunicipality() != null ? finantialInstitution.getMunicipality().getLocalizedName(new Locale("pt")) : "---", finantialInstitution.getAddress()); header.setCompanyAddress(companyAddress); // CompanyID /* * Obtem -se pela concatena??o da conservat?ria do registo comercial * com o n?mero do registo comercial, separados pelo car?cter * espa?o. Nos casos em que n?o existe o registo comercial, deve ser * indicado o NIF. */ header.setCompanyID(finantialInstitution.getComercialRegistrationCode()); // CurrencyCode /* * 1.11 * C?digo de moeda (CurrencyCode) . . . . . . . Preencher com * ?EUR? */ header.setCurrencyCode(finantialInstitution.getCurrency().getCode()); // DateCreated DateTime now = new DateTime(); header.setDateCreated(convertToXMLDateTime(dataTypeFactory, now)); // Email // header.setEmail(StringUtils.EMPTY); // EndDate header.setEndDate(convertToXMLDateTime(dataTypeFactory, endDate)); // Fax // header.setFax(StringUtils.EMPTY); // FiscalYear /* * Utilizar as regras do c?digo do IRC, no caso de per?odos * contabil?sticos n?o coincidentes com o ano civil. (Ex: per?odo de * tributa??o de 01 -10 -2008 a 30 -09 -2009 corresponde FiscalYear * 2008). Inteiro 4 */ header.setFiscalYear(endDate.getYear()); // Ir obter a data do ?ltimo // documento(por causa de submeter em janeiro, documentos de // dezembro) // HeaderComment // header.setHeaderComment(org.apache.commons.lang.StringUtils.EMPTY); // ProductCompanyTaxID // Preencher com o NIF da entidade produtora do software header.setProductCompanyTaxID(SaftConfig.PRODUCT_COMPANY_TAX_ID()); // ProductID /* * 1.16 * Nome do produto (ProductID). . . . . . . . . . . Nome do * produto que gera o SAF -T (PT) . . . . . . . . . . . Deve ser * indicado o nome comercial do software e o da empresa produtora no * formato ?Nome produto/nome empresa?. */ header.setProductID(SaftConfig.PRODUCT_ID()); // Product Version header.setProductVersion(SaftConfig.PRODUCT_VERSION()); // SoftwareCertificateNumber header.setSoftwareCertificateNumber(BigInteger.valueOf(SaftConfig.SOFTWARE_CERTIFICATE_NUMBER())); // StartDate header.setStartDate(dataTypeFactory.newXMLGregorianCalendarDate(startDate.getYear(), startDate.getMonthOfYear(), startDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED)); // TaxAccountingBasis /* * Deve ser preenchido com: contabilidade; facturao; ?I? ? dados * integrados de factura??o e contabilidade; ?S? ? autofactura??o; * ?P? ? dados parciais de factura??o */ header.setTaxAccountingBasis("P"); // TaxEntity /* * Identifica??o do estabelecimento (TaxEntity) No caso do ficheiro * de factura??o dever? ser especificado a que estabelecimento diz * respeito o ficheiro produzido, se aplic?vel, caso contr?rio, * dever? ser preenchido com a especifica??o ?Global?. No caso do * ficheiro de contabilidade ou integrado, este campo dever? ser * preenchido com a especifica??o ?Sede?. Texto 20 */ header.setTaxEntity("Global"); // TaxRegistrationNumber /* * N?mero de identifica??o fiscal da empresa * (TaxRegistrationNumber). Preencher com o NIF portugu?s sem * espa?os e sem qualquer prefixo do pa?s. Inteiro 9 */ try { header.setTaxRegistrationNumber(Integer.parseInt(finantialInstitution.getFiscalNumber())); } catch (Exception ex) { throw new RuntimeException("Invalid Fiscal Number."); } // header.setTelephone(finantialInstitution.get); // header.setWebsite(finantialInstitution.getEmailContact()); return header; } catch (DatatypeConfigurationException e) { e.printStackTrace(); return null; } }
From source file:org.finra.dm.core.DmDateUtils.java
/** * Gets an instance of XMLGregorianCalendar class initialized per the specified java.util.Date value. Returns the current date/time if date is null. * * @param date the java.util.Date value to be converted into XMLGregorianCalendar. * * @return the XMLGregorianCalendar instance initialized per specified date value *///from w w w. j a v a 2 s. c o m public static XMLGregorianCalendar getXMLGregorianCalendarValue(Date date) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); if (date != null) { gregorianCalendar.setTime(date); } try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); } catch (DatatypeConfigurationException ex) { throw new IllegalStateException("Failed to create a new instance of DataTypeFactory.", ex); } }