Example usage for javax.ejb TransactionAttributeType REQUIRED

List of usage examples for javax.ejb TransactionAttributeType REQUIRED

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType REQUIRED.

Prototype

TransactionAttributeType REQUIRED

To view the source code for javax.ejb TransactionAttributeType REQUIRED.

Click Source Link

Document

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

Usage

From source file:be.fedict.trust.service.bean.TrustServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@SNMP(oid = SnmpConstants.VALIDATE_ATTRIBUTE_CERT)
public ValidationResult validateAttributeCertificates(String trustDomainName,
        List<byte[]> encodedAttributeCertificates, List<X509Certificate> certificateChain,
        boolean returnRevocationData) throws TrustDomainNotFoundException {

    LOG.debug("validate attribute certificates");

    TrustLinkerResult lastResult = null;
    RevocationData lastRevocationData = null;
    for (TrustDomainEntity trustDomain : getTrustDomains(trustDomainName)) {

        TrustValidator trustValidator = getTrustValidator(trustDomain, returnRevocationData);
        try {//from  w  w w  . j  a  va2 s  .co m
            trustValidator.isTrusted(encodedAttributeCertificates, certificateChain);
        } catch (CertPathValidatorException e) {
        }

        if (trustValidator.getResult().isValid()) {
            LOG.debug("valid for trust domain: " + trustDomain.getName());
            harvest(trustDomain, certificateChain);
            return new ValidationResult(trustValidator.getResult(), trustValidator.getRevocationData());
        }

        lastResult = trustValidator.getResult();
        lastRevocationData = trustValidator.getRevocationData();
    }

    return new ValidationResult(lastResult, lastRevocationData);
}

From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("_System_")
@Override//w  ww.  j  a v  a2  s  .  c  o  m
public void initialise() throws IOException {
    final PersistenceManager pm = createPersistenceManager();
    try {
        //         SecurityChangeListenerTariffUserSet.register(pm);
        pm.getExtent(PFMoneyFlowMapping.class);
        pm.getExtent(OwnerDimension.class);
        pm.getExtent(PriceFragmentDimension.class);

        MoneyFlowDimension priceFragmentDimension = MoneyFlowDimension.getMoneyFlowDimension(pm,
                PriceFragmentDimension.MONEY_FLOW_DIMENSION_ID);
        if (priceFragmentDimension == null) {
            priceFragmentDimension = new PriceFragmentDimension();
            priceFragmentDimension = pm.makePersistent(priceFragmentDimension);
        }

        MoneyFlowDimension ownerDimension = MoneyFlowDimension.getMoneyFlowDimension(pm,
                OwnerDimension.MONEY_FLOW_DIMENSION_ID);
        if (ownerDimension == null) {
            ownerDimension = new OwnerDimension();
            ownerDimension = pm.makePersistent(ownerDimension);
        }

        MoneyFlowDimension sourceOrgDimension = MoneyFlowDimension.getMoneyFlowDimension(pm,
                SourceOrganisationDimension.MONEY_FLOW_DIMENSION_ID);
        if (sourceOrgDimension == null) {
            sourceOrgDimension = new SourceOrganisationDimension();
            sourceOrgDimension = pm.makePersistent(sourceOrgDimension);
        }

        PayableObjectMoneyTransferFactory invoiceTransferFactory = PayableObjectMoneyTransferFactoryJDO
                .getFactory(pm, null, PartnerPayPayableObjectAccountantDelegate.PAYABLE_OBJECT_FACTORY_SCOPE,
                        Invoice.class);
        if (invoiceTransferFactory == null) {
            invoiceTransferFactory = new InvoiceMoneyTransferFactoryJDO(
                    PartnerPayPayableObjectAccountantDelegate.PAYABLE_OBJECT_FACTORY_SCOPE);
            pm.makePersistent(invoiceTransferFactory);
        }

        pm.getExtent(AccountType.class);
        try {
            pm.getObjectById(AccountType.ACCOUNT_TYPE_ID_UNCOLLECTABLE);
        } catch (final JDOObjectNotFoundException x) {
            final AccountType accountType = pm
                    .makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_UNCOLLECTABLE, false));
            accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Uncollectable");
            accountType.getName().setText(Locale.GERMAN.getLanguage(), "Uneinbringlich");
        }

        pm.getFetchPlan().addGroup(FetchPlan.DEFAULT);
        Price.setDefaultTotalPriceFragmentType(pm.detachCopy(PriceFragmentType.getTotalPriceFragmentType(pm)));

        initRegisterConfigModules(pm);

        BugfixWrongOutstandingFlag.fix(pm);

        UpdateTo12AccountantStructure.update(pm);

        // check, whether the datastore is already initialized
        try {
            pm.getObjectById(AccountType.ACCOUNT_TYPE_ID_OUTSIDE);
            return; // already initialized
        } catch (final JDOObjectNotFoundException x) {
            // datastore not yet initialized
        }

        // Initalise standard property set structures for articleContainers
        InvoiceStruct.getInvoiceStructLocal(pm);

        pm.makePersistent(new ResellerTariffUserSetFactory(Organisation.DEV_ORGANISATION_ID,
                ResellerTariffUserSetFactory.class.getName(), Tariff.class));
        pm.makePersistent(new EntityUserSetNotificationFilterEntry(Organisation.DEV_ORGANISATION_ID,
                Tariff.class.getName(), Tariff.class));

        // create and persist the AccountTypes
        AccountType accountType;
        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_OUTSIDE, true));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Outside");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Auerhalb");

        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_LOCAL_EXPENSE, false));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Expense");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Aufwand");

        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_LOCAL_REVENUE, false));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Revenue");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Einnahme");

        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_PARTNER_CUSTOMER, false));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Customer");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Kunde");

        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_PARTNER_NEUTRAL, false));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Business partner");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Geschftspartner");

        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_PARTNER_VENDOR, false));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Vendor");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Lieferant");

        accountType = pm.makePersistent(new AccountType(AccountType.ACCOUNT_TYPE_ID_SUMMARY, false));
        accountType.getName().setText(Locale.ENGLISH.getLanguage(), "Summary");
        accountType.getName().setText(Locale.GERMAN.getLanguage(), "Summenkonto");

        final Accounting accounting = Accounting.getAccounting(pm);
        final Trader trader = Trader.getTrader(pm);

        final LegalEntity anonymousCustomer = LegalEntity.getAnonymousLegalEntity(pm);
        final CustomerGroup anonymousCustomerGroup = anonymousCustomer.getDefaultCustomerGroup();

        //       create some ModeOfPayments
        // Cash
        ModeOfPayment modeOfPayment = new ModeOfPayment(ModeOfPaymentConst.MODE_OF_PAYMENT_ID_CASH);
        modeOfPayment.getName().setText(Locale.ENGLISH.getLanguage(), "Cash");
        modeOfPayment.getName().setText(Locale.GERMAN.getLanguage(), "Bargeld");
        modeOfPayment.getName().setText(Locale.FRENCH.getLanguage(), "Argent Liquide");
        ModeOfPaymentFlavour modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_CASH);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Cash");
        modeOfPaymentFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Bargeld");
        modeOfPaymentFlavour.getName().setText(Locale.FRENCH.getLanguage(), "Argent Liquide");
        modeOfPaymentFlavour.loadIconFromResource();
        pm.makePersistent(modeOfPayment);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfPayment(modeOfPayment);
        anonymousCustomerGroup.addModeOfPayment(modeOfPayment);

        // we need this later for payment processor registration
        final ModeOfPayment modeOfPaymentCash = modeOfPayment;

        // No payment - this is a dummy MOP which means, the payment is postponed without
        //   specifying a certain real MOP
        modeOfPayment = new ModeOfPayment(ModeOfPaymentConst.MODE_OF_PAYMENT_ID_NON_PAYMENT);
        modeOfPayment.getName().setText(Locale.ENGLISH.getLanguage(), "Non-Payment");
        modeOfPayment.getName().setText(Locale.GERMAN.getLanguage(), "Nichtzahlung");
        modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_NON_PAYMENT);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Non-Payment");
        modeOfPaymentFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Nichtzahlung");
        modeOfPaymentFlavour.loadIconFromResource();
        pm.makePersistent(modeOfPayment);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfPayment(modeOfPayment);

        // we need this later for payment processor registration
        final ModeOfPayment modeOfPaymentNonPayment = modeOfPayment;

        // Credit Card - VISA, Master, AmEx, Diners
        modeOfPayment = new ModeOfPayment(ModeOfPaymentConst.MODE_OF_PAYMENT_ID_CREDIT_CARD);
        modeOfPayment.getName().setText(Locale.ENGLISH.getLanguage(), "Credit Card");
        modeOfPayment.getName().setText(Locale.GERMAN.getLanguage(), "Kreditkarte");
        modeOfPayment.getName().setText(Locale.FRENCH.getLanguage(), "Carte de Crdit");
        modeOfPaymentFlavour = modeOfPayment.createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_VISA);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "VISA");
        modeOfPaymentFlavour.loadIconFromResource();
        modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_MASTER_CARD);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "MasterCard");
        modeOfPaymentFlavour.loadIconFromResource();
        modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_AMERICAN_EXPRESS);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "American Express");
        modeOfPaymentFlavour.loadIconFromResource();
        modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_DINERS_CLUB);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Diners Club");
        modeOfPaymentFlavour.loadIconFromResource();
        pm.makePersistent(modeOfPayment);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfPayment(modeOfPayment);
        anonymousCustomerGroup.addModeOfPayment(modeOfPayment);

        // we need this later for payment processor registration
        final ModeOfPayment modeOfPaymentCreditCard = modeOfPayment;

        // Bank Transfer
        modeOfPayment = new ModeOfPayment(ModeOfPaymentConst.MODE_OF_PAYMENT_ID_BANK_TRANSFER);
        modeOfPayment.getName().setText(Locale.ENGLISH.getLanguage(), "Bank Transfer");
        modeOfPayment.getName().setText(Locale.GERMAN.getLanguage(), "berweisung");
        modeOfPayment.getName().setText(Locale.FRENCH.getLanguage(), "Virement");
        modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_BANK_TRANSFER);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Bank Transfer");
        modeOfPaymentFlavour.getName().setText(Locale.GERMAN.getLanguage(), "berweisung");
        modeOfPaymentFlavour.getName().setText(Locale.FRENCH.getLanguage(), "Virement");
        modeOfPaymentFlavour.loadIconFromResource();
        pm.makePersistent(modeOfPayment);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfPayment(modeOfPayment);

        // we need this later for payment processor registration
        final ModeOfPayment modeOfPaymentBankTransfer = modeOfPayment;

        // Debit Note
        modeOfPayment = new ModeOfPayment(ModeOfPaymentConst.MODE_OF_PAYMENT_ID_DEBIT_NOTE);
        modeOfPayment.getName().setText(Locale.ENGLISH.getLanguage(), "Debit Note");
        modeOfPayment.getName().setText(Locale.GERMAN.getLanguage(), "Lastschrift");
        modeOfPayment.getName().setText(Locale.FRENCH.getLanguage(), "Note de Dbit");
        modeOfPaymentFlavour = modeOfPayment
                .createFlavour(ModeOfPaymentConst.MODE_OF_PAYMENT_FLAVOUR_ID_DEBIT_NOTE);
        modeOfPaymentFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Debit Note");
        modeOfPaymentFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Lastschrift");
        modeOfPaymentFlavour.getName().setText(Locale.FRENCH.getLanguage(), "Note de Dbit");
        modeOfPaymentFlavour.loadIconFromResource();
        pm.makePersistent(modeOfPayment);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfPayment(modeOfPayment);

        // we need this later for payment processor registration
        final ModeOfPayment modeOfPaymentDebitNote = modeOfPayment;

        // create some ServerPaymentProcessors
        final ServerPaymentProcessorCash serverPaymentProcessorCash = ServerPaymentProcessorCash
                .getServerPaymentProcessorCash(pm);
        serverPaymentProcessorCash.getName().setText(Locale.ENGLISH.getLanguage(), "Cash Payment");
        serverPaymentProcessorCash.getName().setText(Locale.GERMAN.getLanguage(), "Barzahlung");
        serverPaymentProcessorCash.getName().setText(Locale.FRENCH.getLanguage(), "Paiement Argent Liquide");
        serverPaymentProcessorCash.addModeOfPayment(modeOfPaymentCash);

        final ServerPaymentProcessorNonPayment serverPaymentProcessorNonPayment = ServerPaymentProcessorNonPayment
                .getServerPaymentProcessorNonPayment(pm);
        serverPaymentProcessorNonPayment.getName().setText(Locale.ENGLISH.getLanguage(),
                "Non-Payment (payment will be postponed)");
        serverPaymentProcessorNonPayment.getName().setText(Locale.GERMAN.getLanguage(),
                "Nichtzahlung (Zahlung wird verschoben)");
        serverPaymentProcessorNonPayment.addModeOfPayment(modeOfPaymentNonPayment);

        final ServerPaymentProcessorCreditCardDummyForClientPayment serverPaymentProcessorCreditCardDummyForClientPayment = ServerPaymentProcessorCreditCardDummyForClientPayment
                .getServerPaymentProcessorCreditCardDummyForClientPayment(pm);
        serverPaymentProcessorCreditCardDummyForClientPayment.getName().setText(Locale.ENGLISH.getLanguage(),
                "Dummy for client-sided Credit Card Payment");
        serverPaymentProcessorCreditCardDummyForClientPayment.getName().setText(Locale.GERMAN.getLanguage(),
                "Pseudo-Modul fr client-seitige Kreditkarten-Zahlungen");
        serverPaymentProcessorCreditCardDummyForClientPayment.addModeOfPayment(modeOfPaymentCreditCard);

        final ServerPaymentProcessorBankTransferGermany serverPaymentProcessorBankTransferGermany = ServerPaymentProcessorBankTransferGermany
                .getServerPaymentProcessorBankTransferGermany(pm);
        serverPaymentProcessorBankTransferGermany.getName().setText(Locale.ENGLISH.getLanguage(),
                "Bank transfer within Germany");
        serverPaymentProcessorBankTransferGermany.getName().setText(Locale.GERMAN.getLanguage(),
                "berweisung innerhalb Deutschlands");
        serverPaymentProcessorBankTransferGermany.addModeOfPayment(modeOfPaymentBankTransfer);

        final ServerPaymentProcessorDebitNoteGermany serverPaymentProcessorDebitNoteGermany = ServerPaymentProcessorDebitNoteGermany
                .getServerPaymentProcessorDebitNoteGermany(pm);
        serverPaymentProcessorDebitNoteGermany.getName().setText(Locale.ENGLISH.getLanguage(),
                "Debit Note within Germany");
        serverPaymentProcessorDebitNoteGermany.getName().setText(Locale.GERMAN.getLanguage(),
                "Lastschrift innerhalb Deutschlands");
        serverPaymentProcessorDebitNoteGermany.addModeOfPayment(modeOfPaymentDebitNote);

        // persist process definitions
        ProcessDefinition processDefinitionInvoiceCustomerLocal;
        processDefinitionInvoiceCustomerLocal = accounting.storeProcessDefinitionInvoice(
                TradeSide.customerLocal,
                ProcessDefinitionAssignment.class.getResource("invoice/customer/local/"));
        pm.makePersistent(new ProcessDefinitionAssignment(Invoice.class, TradeSide.customerLocal,
                processDefinitionInvoiceCustomerLocal));

        ProcessDefinition processDefinitionInvoiceCustomerCrossOrg;
        processDefinitionInvoiceCustomerCrossOrg = accounting.storeProcessDefinitionInvoice(
                TradeSide.customerCrossOrganisation,
                ProcessDefinitionAssignment.class.getResource("invoice/customer/crossorganisation/"));
        pm.makePersistent(new ProcessDefinitionAssignment(Invoice.class, TradeSide.customerCrossOrganisation,
                processDefinitionInvoiceCustomerCrossOrg));

        ProcessDefinition processDefinitionInvoiceVendor;
        processDefinitionInvoiceVendor = accounting.storeProcessDefinitionInvoice(TradeSide.vendor,
                ProcessDefinitionAssignment.class.getResource("invoice/vendor/"));
        pm.makePersistent(new ProcessDefinitionAssignment(Invoice.class, TradeSide.vendor,
                processDefinitionInvoiceVendor));

        // deactive IDGenerator's cache for invoice
        final IDNamespaceDefault idNamespaceDefault = IDNamespaceDefault.createIDNamespaceDefault(pm,
                getOrganisationID(), Invoice.class);
        idNamespaceDefault.setCacheSizeServer(0);
        idNamespaceDefault.setCacheSizeClient(0);

        pm.makePersistent(new EditLockTypeInvoice(EditLockTypeInvoice.EDIT_LOCK_TYPE_ID));

    } finally {
        pm.close();
    }
}

From source file:com.flexive.ejb.beans.TreeEngineBean.java

/**
 * {@inheritDoc}//w  w w .  ja va  2  s  .c  om
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long[] createNodes(FxTreeMode mode, long parentNodeId, int position, String path)
        throws FxApplicationException {
    Connection con = null;
    if (mode == FxTreeMode.Live)
        throw new FxCreateException("ex.tree.create.live");
    try {
        con = Database.getDbConnection();
        boolean ok = false;
        try {
            long[] nodes = StorageManager.getTreeStorage().createNodes(con, seq, contentEngine, mode,
                    parentNodeId, path, position, true);
            // call scripts
            final List<Long> scriptIds = scripting.getByScriptEvent(FxScriptEvent.AfterTreeNodeAdded);
            if (scriptIds.size() == 0) {
                ok = true;
                return nodes;
            }
            final FxScriptBinding binding = new FxScriptBinding();
            for (long node : nodes) {
                binding.setVariable("node", getNode(mode, node));
                for (long scriptId : scriptIds)
                    scripting.runScript(scriptId, binding);
            }
            ok = true;
            return nodes;
        } finally {
            if (ok && !ctx.getRollbackOnly()) {
                FxContext.get().setTreeWasModified();
                StorageManager.getTreeStorage().checkTreeIfEnabled(con, mode);
            }
        }
    } catch (FxApplicationException ae) {
        EJBUtils.rollback(ctx);
        throw ae;
    } catch (Throwable t) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, t, "ex.tree.create.failed", path);
    } finally {
        Database.closeObjects(TreeEngineBean.class, con, null);
    }
}

From source file:com.flexive.ejb.beans.workflow.StepEngineBean.java

/**
 * {@inheritDoc}//from   ww w.  ja  va2  s.  co  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeSteps(long workflowId) throws FxApplicationException {
    deleteStep(workflowId, true);
}

From source file:com.flexive.ejb.beans.structure.SelectListEngineBean.java

/**
 * {@inheritDoc}// ww  w. j a  v a2s .c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(FxSelectList list) throws FxApplicationException {
    //        System.out.println("Removing list " + list.getLabel());
    FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.SelectListEditor);
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        //fix list references
        StringBuilder sb = new StringBuilder(500).append("UPDATE ").append(TBL_STRUCT_SELECTLIST)
                .append(" SET PARENTID=? WHERE PARENTID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setNull(1, java.sql.Types.INTEGER);
        ps.setLong(2, list.getId());
        ps.executeUpdate();
        ps.close();
        sb.setLength(0);
        //list translations
        sb.append("DELETE FROM ").append(TBL_STRUCT_SELECTLIST).append(ML).append(" WHERE ID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setLong(1, list.getId());
        ps.executeUpdate();
        ps.close();
        sb.setLength(0);
        //item translations
        sb.append("DELETE FROM ").append(TBL_STRUCT_SELECTLIST_ITEM).append(ML)
                .append(" WHERE ID IN(SELECT DISTINCT ID FROM ").append(TBL_STRUCT_SELECTLIST_ITEM)
                .append(" WHERE LISTID=?)");
        ps = con.prepareStatement(sb.toString());
        ps.setLong(1, list.getId());
        ps.executeUpdate();
        ps.close();
        sb.setLength(0);
        //fix item references
        ps = con.prepareStatement(StorageManager.getSelectListItemReferenceFixStatement());
        ps.setNull(1, java.sql.Types.INTEGER);
        ps.setLong(2, list.getId());
        ps.executeUpdate();
        ps.close();
        //items
        sb.append("DELETE FROM ").append(TBL_STRUCT_SELECTLIST_ITEM).append(" WHERE LISTID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setLong(1, list.getId());
        ps.executeUpdate();
        ps.close();
        sb.setLength(0);
        //the entry itself
        sb.append("DELETE FROM ").append(TBL_STRUCT_SELECTLIST).append(" WHERE ID=?");
        ps = con.prepareStatement(sb.toString());
        ps.setLong(1, list.getId());
        ps.executeUpdate();
        StructureLoader.reload(null);
    } catch (SQLException e) {
        e.printStackTrace();
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } catch (FxCacheException e1) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, e1, "ex.cache", e1.getMessage());
    } finally {
        Database.closeObjects(TypeEngineBean.class, con, ps);
    }
}

From source file:com.flexive.ejb.beans.workflow.StepEngineBean.java

/**
 * {@inheritDoc}//from w w w.  j a va  2s .  c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeStep(long stepId) throws FxApplicationException {
    deleteStep(stepId, false);
}

From source file:com.flexive.ejb.beans.LanguageBean.java

/**
 * {@inheritDoc}/*from   www  . ja  v a  2s  .  co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void setAvailable(List<FxLanguage> available, boolean ignoreUsage) throws FxApplicationException {
    FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.GlobalSupervisor);
    Connection con = null;
    PreparedStatement ps = null;
    if (available == null || available.size() == 0)
        throw new FxInvalidParameterException("available", "ex.language.noAvailable");
    try {
        con = Database.getDbConnection();
        if (!ignoreUsage) {
            List<FxLanguage> orgLang = loadAvailable(true);
            boolean found;
            for (FxLanguage org : orgLang) {
                found = false;
                for (FxLanguage tmp : available) {
                    if (tmp.getId() == org.getId()) {
                        found = true;
                        break;
                    }
                }
                if (!found && hasUsages(con, org))
                    throw new FxInvalidParameterException("available", "ex.language.removeUsed",
                            org.getLabel());
            }
        }
        ps = con.prepareStatement("UPDATE " + TBL_LANG + " SET INUSE=?, DISPPOS=?");
        ps.setBoolean(1, false);
        ps.setNull(2, java.sql.Types.INTEGER);
        ps.executeUpdate();
        ps.close();
        int pos = 0;
        ps = con.prepareStatement("UPDATE " + TBL_LANG + " SET INUSE=?, DISPPOS=? WHERE LANG_CODE=?");
        ps.setBoolean(1, true);
        for (FxLanguage lang : available) {
            ps.setInt(2, pos++);
            ps.setLong(3, lang.getId());
            ps.addBatch();
        }
        ps.executeBatch();
        StructureLoader.updateLanguages(FxContext.get().getDivisionId(), loadAll(true, true));
    } catch (FxCacheException e) {
        LOG.error(e, e);
    } catch (SQLException e) {
        throw new FxUpdateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(LanguageBean.class, con, ps);
    }
}

From source file:com.flexive.ejb.beans.UserGroupEngineBean.java

/**
 * {@inheritDoc}//  w  ww.ja  v a2  s  .  co  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void update(long groupId, String name, String color) throws FxApplicationException {

    final UserTicket ticket = FxContext.getUserTicket();

    // Load the group
    UserGroup aGroup = CacheAdmin.getEnvironment().getUserGroup(groupId);

    // Permission checks
    checkPermission(aGroup, "ex.usergroup.noUpdatePerms");

    Connection con = null;
    Statement stmt = null;
    PreparedStatement pstmt;
    String sCurSql = null;
    try {

        // Sanity checks
        if (color != null && color.length() > 0 && color.charAt(0) != '#') {
            color = "#" + color;
        }
        checkName(name);

        // Fill in new values
        if (StringUtils.isNotBlank(name))
            aGroup.setName(name);
        if (StringUtils.isNotBlank(color))
            aGroup.setColor(color);

        // Obtain a database connection
        con = Database.getDbConnection();

        // Create the new group
        sCurSql = "UPDATE " + TBL_USERGROUPS + " SET " + "NAME=?, COLOR=?, MODIFIED_BY=?, MODIFIED_AT=? "
                + "WHERE ID=" + groupId;
        final long NOW = System.currentTimeMillis();
        pstmt = con.prepareStatement(sCurSql);
        pstmt.setString(1, aGroup.getName());
        pstmt.setString(2, aGroup.getColor());
        pstmt.setLong(3, ticket.getUserId());
        pstmt.setLong(4, NOW);
        pstmt.executeUpdate();
        pstmt.close();

        StructureLoader.updateUserGroups(FxContext.get().getDivisionId(), loadAll(-1));
    } catch (SQLException exc) {
        final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc);
        EJBUtils.rollback(ctx);
        if (uniqueConstraintViolation) {
            FxEntryExistsException eee = new FxEntryExistsException("ex.usergroup.groupExists", name);
            if (LOG.isInfoEnabled())
                LOG.info(eee);
            throw eee;
        } else {
            FxCreateException ce = new FxCreateException(exc, "ex.usergroup.sqlError", exc.getMessage(),
                    sCurSql);
            LOG.error(ce);
            throw ce;
        }
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }
}

From source file:com.flexive.ejb.beans.ACLEngineBean.java

/**
 * {@inheritDoc}//from w  w w.  j  a va  2 s .c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void update(long id, String name, FxString label, String color, String description,
        List<ACLAssignment> assignments) throws FxApplicationException {
    UserTicket ticket = FxContext.getUserTicket();
    boolean keepAssignment = assignments == null;
    // Load the current version of the ACL
    ACL theACL = load(id);
    List<ACLAssignment> orgAssignments = null;
    if (!keepAssignment)
        orgAssignments = loadAssignments(id);

    // Check the assignments array: Every group may only be contained once
    if (assignments == null) {
        assignments = new ArrayList<ACLAssignment>(0);
    } else if (assignments.size() > 0) {
        Hashtable<Long, Boolean> uniqueCheck = new Hashtable<Long, Boolean>(assignments.size());
        for (ACLAssignment ass : assignments) {
            // Group defined more than once in the list?
            if (uniqueCheck.put(ass.getGroupId(), Boolean.TRUE) != null) {
                String groupName = "unknown";
                try {
                    groupName = CacheAdmin.getEnvironment().getUserGroup(ass.getGroupId()).getName();
                } catch (Throwable t) {
                    //ignore
                }
                throw new FxUpdateException("ex.aclAssignment.update.groupDefinedMoreThanOnce",
                        theACL.getName(), groupName);
            }
        }
    }

    // Security
    if (!ticket.isGlobalSupervisor()) {
        // Security
        if (!ticket.isInRole(Role.MandatorSupervisor) && !ticket.isInRole(Role.ACLManagement))
            throw new FxNoAccessException(LOG, "ex.acl.updateFailed.noPermission", theACL.getName());
        if (ticket.getMandatorId() != theACL.getMandatorId())
            throw new FxNoAccessException(LOG, "ex.acl.updateFailed.foreignMandator", theACL.getName());
    }

    // Parameter checks
    if (color != null)
        color = FxFormatUtils.processColorString("COLOR", color);
    if (name != null)
        name = checkName(name);
    if (label != null)
        label = checkLabel(label);
    if (description != null)
        description = checkDescription(description);

    // Set values
    if (color != null)
        theACL.setColor(color);
    if (name != null)
        theACL.setName(name);
    if (label != null)
        theACL.setLabel(label);
    if (description != null)
        theACL.setDescription(description);

    Connection con = null;
    PreparedStatement stmt = null;
    String curSql;

    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        curSql = "UPDATE " + TBL_ACLS + " SET " +
        //       1         2        3            4           5         6
                "cat_type=?,color=?,description=?,name=?,modified_by=?,modified_at=? WHERE id=" + id;
        final long NOW = System.currentTimeMillis();
        stmt = con.prepareStatement(curSql);
        stmt.setInt(1, theACL.getCategory().getId());
        stmt.setString(2, theACL.getColor());
        stmt.setString(3, theACL.getDescription());
        stmt.setString(4, theACL.getName());
        stmt.setLong(5, ticket.getUserId());
        stmt.setLong(6, NOW);
        final int uCount = stmt.executeUpdate();
        stmt.close();
        if (uCount != 1) {
            throw new SQLException(uCount + " rows affected instead of 1");
        }
        Database.storeFxString(theACL.getLabel(), con, TBL_ACLS, "LABEL", "ID", theACL.getId());
        final List<Long> affectedUserGroupIds = new ArrayList<Long>();
        if (!keepAssignment) {
            //remove assignments
            curSql = "DELETE FROM " + TBL_ACLS_ASSIGNMENT + " WHERE ACL=?";
            stmt = con.prepareStatement(curSql);
            stmt.setLong(1, theACL.getId());
            stmt.executeUpdate();
            if (assignments.size() > 0) {
                stmt.close();
                //                                             1          2    3      4        5        6     7      8
                curSql = "INSERT INTO " + TBL_ACLS_ASSIGNMENT
                        + " (USERGROUP, ACL, PEDIT, PREMOVE, PEXPORT, PREL, PREAD, PCREATE, " +
                        //9          10          11           12
                        "CREATED_BY, CREATED_AT, MODIFIED_BY, MODIFIED_AT) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
                stmt = con.prepareStatement(curSql);
                stmt.setLong(2, theACL.getId());
                stmt.setLong(9, ticket.getUserId());
                stmt.setLong(10, NOW);
                stmt.setLong(11, ticket.getUserId());
                stmt.setLong(12, NOW);
                for (ACLAssignment assignment : assignments) {
                    affectedUserGroupIds.add(assignment.getGroupId());
                    stmt.setLong(1, assignment.getGroupId());
                    stmt.setBoolean(3, assignment.getMayEdit());
                    stmt.setBoolean(4, assignment.getMayDelete());
                    stmt.setBoolean(5, assignment.getMayExport());
                    stmt.setBoolean(6, assignment.getMayRelate());
                    stmt.setBoolean(7, assignment.getMayRead());
                    stmt.setBoolean(8, assignment.getMayCreate());
                    if (assignment.getMayCreate() || assignment.getMayDelete() || assignment.getMayEdit()
                            || assignment.getMayExport() || assignment.getMayRelate()
                            || assignment.getMayRead())
                        stmt.executeUpdate();
                }

                // update usertickets of affected groups
                for (Long groupId : affectedUserGroupIds) {
                    UserTicketStore.flagDirtyHavingGroupId(groupId);
                }
            }
        }
        try {
            StructureLoader.updateACL(FxContext.get().getDivisionId(), this.load(id));
        } catch (FxLoadException e) {
            LOG.error(e, e);
        } catch (FxNotFoundException e) {
            LOG.error(e, e);
        }
        StringBuilder sbHistory = new StringBuilder(1000);
        final XStream xStream = ConversionEngine.getXStream();
        sbHistory.append("<original>\n").append(xStream.toXML(theACL)).append("</original>\n");
        if (orgAssignments != null) {
            sbHistory.append("<originalAssignments>\n");
            for (ACLAssignment aa : orgAssignments)
                sbHistory.append(xStream.toXML(aa));
            sbHistory.append("</originalAssignments>\n");
        }
        sbHistory.append("<new>\n").append(xStream.toXML(CacheAdmin.getEnvironment().getACL(id)))
                .append("</new>\n");
        if (orgAssignments != null) {
            sbHistory.append("<newAssignments>\n");
            for (ACLAssignment aa : loadAssignments(id))
                sbHistory.append(xStream.toXML(aa));
            sbHistory.append("</newAssignments>\n");
        }
        EJBLookup.getHistoryTrackerEngine().trackData(sbHistory.toString(), "history.acl.update",
                theACL.getName());
    } catch (SQLException exc) {
        final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc);
        EJBUtils.rollback(ctx);
        if (uniqueConstraintViolation)
            throw new FxEntryExistsException(LOG, "ex.acl.updateFailed.nameTaken", theACL.getName(), name);
        else
            throw new FxUpdateException(LOG, "ex.acl.updateFailed", theACL.getName(), exc.getMessage());
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }

}

From source file:org.nightlabs.jfire.store.StoreManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("_System_")
@Override/*w  w w.  ja v a 2 s  .  c o m*/
public void initialise() throws Exception {
    PersistenceManager pm = createPersistenceManager();
    try {
        initRegisterConfigModules(pm);

        initTimerTaskCalculateProductTypeAvailabilityPercentage(pm);

        pm.getExtent(ModeOfDelivery.class);
        try {
            pm.getObjectById(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_MANUAL);

            // it already exists, hence initialization is already done
            return;
        } catch (JDOObjectNotFoundException x) {
            // not yet initialized
        }

        pm.getExtent(ProductTypePermissionFlagSet.class); // We must already initialize the meta data here, because otherwise we run into deadlocks.

        SecurityChangeListenerProductTypePermission.register(pm);

        DefaultLocalStorekeeperDelegate.getDefaultLocalStorekeeperDelegate(pm);

        // Initalise standard property set structures for articleContainers
        DeliveryNoteStruct.getDeliveryNoteStructLocal(pm);
        ReceptionNoteStruct.getReceptionNoteStructLocal(pm);

        // create & persist instances of RepositoryType
        RepositoryType repositoryType;

        repositoryType = pm.makePersistent(new RepositoryType(RepositoryType.REPOSITORY_TYPE_ID_HOME, false));
        repositoryType.getName().setText(Locale.ENGLISH.getLanguage(), "Home");
        repositoryType.getName().setText(Locale.GERMAN.getLanguage(), "Heim");

        repositoryType = pm.makePersistent(new RepositoryType(RepositoryType.REPOSITORY_TYPE_ID_OUTSIDE, true));
        repositoryType.getName().setText(Locale.ENGLISH.getLanguage(), "Outside");
        repositoryType.getName().setText(Locale.GERMAN.getLanguage(), "Auerhalb");

        repositoryType = pm
                .makePersistent(new RepositoryType(RepositoryType.REPOSITORY_TYPE_ID_PARTNER, false));
        repositoryType.getName().setText(Locale.ENGLISH.getLanguage(), "Business partner");
        repositoryType.getName().setText(Locale.GERMAN.getLanguage(), "Geschftspartner");

        Store store = Store.getStore(pm);
        Trader trader = Trader.getTrader(pm);

        LegalEntity anonymousCustomer = LegalEntity.getAnonymousLegalEntity(pm);
        CustomerGroup anonymousCustomerGroup = anonymousCustomer.getDefaultCustomerGroup();

        //       create fundamental set of ModeOfDelivery/ModeOfDeliveryFlavour
        // manual
        ModeOfDelivery modeOfDelivery = new ModeOfDelivery(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_MANUAL);
        modeOfDelivery.getName().setText(Locale.ENGLISH.getLanguage(),
                "Personal Delivery (manually from hand to hand)");
        modeOfDelivery.getName().setText(Locale.GERMAN.getLanguage(),
                "Persnliche Lieferung (manuell von Hand zu Hand)");
        ModeOfDeliveryFlavour modeOfDeliveryFlavour = modeOfDelivery
                .createFlavour(Organisation.DEV_ORGANISATION_ID, "manual");
        modeOfDeliveryFlavour.loadIconFromResource();
        modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(),
                "Personal Delivery (manually from hand to hand)");
        modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(),
                "Persnliche Lieferung (manuell von Hand zu Hand)");
        modeOfDelivery = pm.makePersistent(modeOfDelivery);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfDelivery(modeOfDelivery);
        anonymousCustomerGroup.addModeOfDelivery(modeOfDelivery);

        ModeOfDelivery modeOfDeliveryManual = modeOfDelivery;

        // nonDelivery
        modeOfDelivery = new ModeOfDelivery(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_NON_DELIVERY);
        modeOfDelivery.getName().setText(Locale.ENGLISH.getLanguage(), "Non-Delivery");
        modeOfDelivery.getName().setText(Locale.GERMAN.getLanguage(), "Nichtlieferung");
        modeOfDeliveryFlavour = modeOfDelivery.createFlavour(Organisation.DEV_ORGANISATION_ID, "nonDelivery");
        modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Non-Delivery");
        modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Nichtlieferung");
        modeOfDelivery = pm.makePersistent(modeOfDelivery);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfDelivery(modeOfDelivery);
        ModeOfDelivery modeOfDeliveryNonDelivery = modeOfDelivery;

        // mailing.physical
        modeOfDelivery = new ModeOfDelivery(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_MAILING_PHYSICAL);
        modeOfDelivery.getName().setText(Locale.ENGLISH.getLanguage(), "Mailing delivery (physical)");
        modeOfDelivery.getName().setText(Locale.GERMAN.getLanguage(), "Postversand (physisch)");
        modeOfDeliveryFlavour = modeOfDelivery.createFlavour(Organisation.DEV_ORGANISATION_ID,
                "mailing.physical.default");
        modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(),
                "Mailing delivery via default service provider");
        modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(),
                "Postversand via Standard-Dienstleister");
        ModeOfDeliveryFlavour modeOfDeliveryFlavourMailingPhysicalDefault = modeOfDeliveryFlavour;
        //         modeOfDeliveryFlavour = modeOfDelivery.createFlavour(Organisation.DEV_ORGANISATION_ID, "mailing.physical.DHL");
        //         modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Mailing delivery via DHL");
        //         modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Postversand via DHL");
        //         modeOfDeliveryFlavour = modeOfDelivery.createFlavour(Organisation.DEV_ORGANISATION_ID, "mailing.physical.UPS");
        //         modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Mailing delivery via UPS");
        //         modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Postversand via UPS");
        modeOfDelivery = pm.makePersistent(modeOfDelivery);
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfDelivery(modeOfDelivery);
        anonymousCustomerGroup.addModeOfDelivery(modeOfDelivery);

        // mailing.virtual
        modeOfDelivery = new ModeOfDelivery(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_MAILING_VIRTUAL);
        modeOfDelivery.getName().setText(Locale.ENGLISH.getLanguage(), "Virtual Delivery (online)");
        modeOfDelivery.getName().setText(Locale.GERMAN.getLanguage(), "Virtuelle Lieferung (online)");
        //         modeOfDeliveryFlavour = modeOfDelivery.createFlavour(Organisation.DEV_ORGANISATION_ID, "mailing.virtual.email");
        //         modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Delivery by eMail");
        //         modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(), "Zustellung via eMail");
        //         pm.makePersistent(modeOfDelivery);
        //         trader.getDefaultCustomerGroupForKnownCustomer().addModeOfDelivery(modeOfDelivery);
        //         anonymousCustomerGroup.addModeOfDelivery(modeOfDelivery);

        modeOfDelivery = new ModeOfDelivery(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_JFIRE);
        modeOfDelivery.getName().setText(Locale.ENGLISH.getLanguage(), "JFire Internal Delivery");
        modeOfDelivery.getName().setText(Locale.GERMAN.getLanguage(), "JFire-interne Lieferung");
        modeOfDeliveryFlavour = modeOfDelivery
                .createFlavour(ModeOfDeliveryConst.MODE_OF_DELIVERY_FLAVOUR_ID_JFIRE);
        ModeOfDeliveryFlavour modeOfDeliveryFlavourJFire = modeOfDeliveryFlavour;
        modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "JFire Internal Delivery");
        modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(), "JFire-interne Lieferung");
        modeOfDelivery = pm.makePersistent(modeOfDelivery);
        //         trader.getDefaultCustomerGroupForKnownCustomer().addModeOfDelivery(modeOfDelivery);
        //         anonymousCustomerGroup.addModeOfDelivery(modeOfDelivery);

        // deliveryQueue
        modeOfDelivery = new ModeOfDelivery(ModeOfDeliveryConst.MODE_OF_DELIVERY_ID_DELIVER_TO_DELIVERY_QUEUE);
        modeOfDelivery.getName().setText(Locale.ENGLISH.getLanguage(), "Deliver to Delivery Queue");
        modeOfDelivery.getName().setText(Locale.GERMAN.getLanguage(), "Lieferung in Lieferwarteschlange");
        modeOfDeliveryFlavour = modeOfDelivery.createFlavour(Organisation.DEV_ORGANISATION_ID,
                "deliverToDeliveryQueue");
        modeOfDeliveryFlavour.getName().setText(Locale.ENGLISH.getLanguage(), "Deliver to Delivery Queue");
        modeOfDeliveryFlavour.getName().setText(Locale.GERMAN.getLanguage(),
                "Lieferung in Lieferwarteschlange");
        modeOfDelivery = pm.makePersistent(modeOfDelivery);
        ModeOfDelivery modeOfDeliveryDeliveryQueue = modeOfDelivery;
        trader.getDefaultCustomerGroupForKnownCustomer().addModeOfDelivery(modeOfDelivery);
        anonymousCustomerGroup.addModeOfDelivery(modeOfDeliveryDeliveryQueue);

        // create some ServerDeliveryProcessor s
        ServerDeliveryProcessorManual serverDeliveryProcessorManual = ServerDeliveryProcessorManual
                .getServerDeliveryProcessorManual(pm);
        serverDeliveryProcessorManual.addModeOfDelivery(modeOfDeliveryManual);
        serverDeliveryProcessorManual.getName().setText(Locale.ENGLISH.getLanguage(),
                "Manual Delivery (no digital action)");
        serverDeliveryProcessorManual.getName().setText(Locale.GERMAN.getLanguage(),
                "Manuelle Lieferung (nicht-digitale Aktion)");

        ServerDeliveryProcessorNonDelivery serverDeliveryProcessorNonDelivery = ServerDeliveryProcessorNonDelivery
                .getServerDeliveryProcessorNonDelivery(pm);
        serverDeliveryProcessorNonDelivery.addModeOfDelivery(modeOfDeliveryNonDelivery);
        serverDeliveryProcessorNonDelivery.getName().setText(Locale.ENGLISH.getLanguage(),
                "Non-Delivery (delivery will be postponed)");
        serverDeliveryProcessorNonDelivery.getName().setText(Locale.GERMAN.getLanguage(),
                "Nichtlieferung (Lieferung wird verschoben)");

        ServerDeliveryProcessorMailingPhysicalDefault serverDeliveryProcessorMailingPhysicalDefault = ServerDeliveryProcessorMailingPhysicalDefault
                .getServerDeliveryProcessorMailingPhysicalDefault(pm);
        serverDeliveryProcessorMailingPhysicalDefault
                .addModeOfDeliveryFlavour(modeOfDeliveryFlavourMailingPhysicalDefault);
        serverDeliveryProcessorMailingPhysicalDefault.getName().setText(Locale.ENGLISH.getLanguage(),
                "Physical mail via default service provider");
        serverDeliveryProcessorMailingPhysicalDefault.getName().setText(Locale.GERMAN.getLanguage(),
                "Postversand via Standard-Dienstleister");

        ServerDeliveryProcessorDeliveryQueue serverDeliveryProcessorDeliveryQueue = ServerDeliveryProcessorDeliveryQueue
                .getServerDeliveryProcessorDeliveryQueue(pm);
        serverDeliveryProcessorDeliveryQueue.addModeOfDelivery(modeOfDeliveryDeliveryQueue);

        ServerDeliveryProcessorJFire serverDeliveryProcessorJFire = ServerDeliveryProcessorJFire
                .getServerDeliveryProcessorJFire(pm);
        serverDeliveryProcessorJFire.addModeOfDeliveryFlavour(modeOfDeliveryFlavourJFire);
        serverDeliveryProcessorJFire.getName().setText(Locale.ENGLISH.getLanguage(), "JFire Internal Delivery");

        // persist process definitions
        ProcessDefinition processDefinitionDeliveryNoteCustomerLocal;
        processDefinitionDeliveryNoteCustomerLocal = store.storeProcessDefinitionDeliveryNote(
                TradeSide.customerLocal,
                ProcessDefinitionAssignment.class.getResource("deliverynote/customer/local/"));
        pm.makePersistent(new ProcessDefinitionAssignment(DeliveryNote.class, TradeSide.customerLocal,
                processDefinitionDeliveryNoteCustomerLocal));

        ProcessDefinition processDefinitionDeliveryNoteCustomerCrossOrg;
        processDefinitionDeliveryNoteCustomerCrossOrg = store.storeProcessDefinitionDeliveryNote(
                TradeSide.customerCrossOrganisation,
                ProcessDefinitionAssignment.class.getResource("deliverynote/customer/crossorganisation/"));
        pm.makePersistent(new ProcessDefinitionAssignment(DeliveryNote.class,
                TradeSide.customerCrossOrganisation, processDefinitionDeliveryNoteCustomerCrossOrg));

        ProcessDefinition processDefinitionDeliveryNoteVendor;
        processDefinitionDeliveryNoteVendor = store.storeProcessDefinitionDeliveryNote(TradeSide.vendor,
                ProcessDefinitionAssignment.class.getResource("deliverynote/vendor/"));
        pm.makePersistent(new ProcessDefinitionAssignment(DeliveryNote.class, TradeSide.vendor,
                processDefinitionDeliveryNoteVendor));

        ProcessDefinition processDefinitionReceptionNoteCustomer;
        processDefinitionReceptionNoteCustomer = store.storeProcessDefinitionReceptionNote(
                TradeSide.customerCrossOrganisation,
                ProcessDefinitionAssignment.class.getResource("receptionnote/customer/crossorganisation/"));
        pm.makePersistent(new ProcessDefinitionAssignment(ReceptionNote.class,
                TradeSide.customerCrossOrganisation, processDefinitionReceptionNoteCustomer));

        // TODO create and persist ProcessDefinition for ReceptionNote.Vendor
        // TODO and for customerLocal

        IDNamespaceDefault idNamespaceDefault = IDNamespaceDefault.createIDNamespaceDefault(pm,
                getOrganisationID(), DeliveryNote.class);
        idNamespaceDefault.setCacheSizeServer(0);
        idNamespaceDefault.setCacheSizeClient(0);

        pm.makePersistent(new EditLockTypeDeliveryNote(EditLockTypeDeliveryNote.EDIT_LOCK_TYPE_ID));

        Unit unit = new Unit(Organisation.DEV_ORGANISATION_ID, "h", 2);
        unit.getSymbol().setText(Locale.ENGLISH.getLanguage(), "h");
        unit.getName().setText(Locale.ENGLISH.getLanguage(), "hour");
        unit.getName().setText(Locale.GERMAN.getLanguage(), "Stunde");
        pm.makePersistent(unit);

        unit = new Unit(Organisation.DEV_ORGANISATION_ID, "piece", 3);
        unit.getSymbol().setText(Locale.ENGLISH.getLanguage(), "pcs.");
        unit.getName().setText(Locale.ENGLISH.getLanguage(), "pieces");
        unit.getSymbol().setText(Locale.GERMAN.getLanguage(), "Stk.");
        unit.getName().setText(Locale.GERMAN.getLanguage(), "Stck");
        pm.makePersistent(unit);

        unit = new Unit(Organisation.DEV_ORGANISATION_ID, "flatRate", 0);
        unit.getSymbol().setText(Locale.ENGLISH.getLanguage(), "()");
        unit.getName().setText(Locale.ENGLISH.getLanguage(), "(flat-rate)");
        unit.getSymbol().setText(Locale.GERMAN.getLanguage(), "()");
        unit.getName().setText(Locale.GERMAN.getLanguage(), "(pauschal)");
        pm.makePersistent(unit);

    } finally {
        pm.close();
    }
}