Example usage for org.dom4j Element getTextTrim

List of usage examples for org.dom4j Element getTextTrim

Introduction

In this page you can find the example usage for org.dom4j Element getTextTrim.

Prototype

String getTextTrim();

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.neuclear.asset.fees.FeeStructureReader.java

License:Open Source License

private static double readAmount(NumberFormat format, Element elem) throws InvalidNamedObjectException {
    if (elem == null)
        return 0;
    String text = elem.getTextTrim();
    if (Utility.isEmpty(text))
        throw new InvalidNamedObjectException("Fee Parse Error", "Empty tag");
    try {/*from   w  w  w . j a  v a 2s  .c  o  m*/
        return format.parse(text).doubleValue();
    } catch (ParseException e) {
        throw new InvalidNamedObjectException("Fee Parse Error", e);
    }
}

From source file:org.neuclear.asset.orders.TransferGlobals.java

License:Open Source License

public static String getElementValue(final Element value) throws InvalidNamedObjectException {
    final String text = value.getTextTrim();
    if (Utility.isEmpty(text))
        throw new InvalidNamedObjectException("Required element is empty");
    return text;//from   w  w w . ja  va 2 s.com
}

From source file:org.neuclear.asset.orders.TransferGlobals.java

License:Open Source License

public static String parseCommentElement(final Element element) {
    final Element value = element.element(createQName(COMMENT_TAG));
    if (value == null)
        return "";
    final String text = value.getTextTrim();
    return Utility.denullString(text);
}

From source file:org.neuclear.asset.orders.TransferGlobals.java

License:Open Source License

public static final Timestamp parseTimeStampElement(final Element elem, final QName qn)
        throws InvalidNamedObjectException {
    try {/* w ww .  jav  a  2  s.c  o m*/
        final Element telem = elem.element(qn);
        if (telem == null)
            throw new InvalidNamedObjectException("missing time stamp element");
        final String value = telem.getTextTrim();
        if (Utility.isEmpty(value))
            throw new InvalidNamedObjectException("missing time stamp");

        return TimeTools.parseTimeStamp(value);
    } catch (ParseException e) {
        throw new InvalidNamedObjectException("missing or invalid time stamp");
    }

}

From source file:org.neuclear.id.Identity.java

License:LGPL

protected static String extractNickName(final Element elem, final SignedNamedCore core) {
    final Element namelement = XMLTools.getByID(elem, "nickname");
    final String name = (namelement != null) ? namelement.getTextTrim() : core.getName();
    return name;//from   ww  w  . j  a v a 2  s .com
}

From source file:org.neuclear.id.signers.SigningServlet.java

protected void handleInputStream(InputStream is, HttpServletRequest request, HttpServletResponse response)
        throws IOException, NeuClearException, XMLException {
    SignatureRequest sigreq = (SignatureRequest) VerifyingReader.getInstance().read(is);
    if (sigreq == null) {
        throw new NeuClearException("nothing to sign");
    }//  w  ww . j a v a2 s. co m
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("text/html");
    final PrintWriter out = response.getWriter();
    out.println("<html><head><title>");
    out.println(getTitle());
    out.println("</title><style>\n\t#banner {\n"
            + "\t\tfont-family:Arial Rounded MT Bold, \"Bitstream Vera Sans\",\"Trebuchet MS\", verdana, lucida, arial, helvetica, sans-serif;\n"
            + "\t\ttext-align: left;\n" + "\t\tcolor:#FFF;\n" + "\t\tfont-size:24px;\n"
            + "\t\tfont-weight:bolder;\n" + "\t\tborder-top:10px solid #FFFFFF;\n"
            + "\t\tborder-bottom:2px solid #009;\n" + "  \t\tbackground:#0000FF;\n"
            + "  \t\tpadding-left:15px;\n" + "\t\tpadding-top:3px;\n" + "\t\tpadding-bottom:3px;\n" + "\n"
            + "\t\tletter-spacing: .2em;\n" + "\t\t}\nbody\t{\n" + "\t\tbackground: #FFF ;\n"
            + "\t\tcolor: black;\n" + "        margin:0px 0px 10px 0px;\n"
            + "\t\tborder-top: 5px solid #white;\n" + "\t\ttext-align: left;\n"
            + "\t\tfont-family: \"Trebuchet MS\", \"Bitstream Vera Sans\", verdana, lucida, arial, helvetica, sans-serif;\n"
            + "\t\tfont-size: small;\n" + "\t\tpadding-bottom: 25px;\n"
            + "\t}\n#content {margin-left:20;margin-right:20;background:#F0F0FF;}\n"
            + "\t#log {background: #008;font-size:14px;font-weight:bolder;color:white;}"
            + "</style></head><body><div id=\"banner\">NeuClear Personal Trader</div>");
    final String endpoint = request.getParameter("endpoint");
    final String receiver = request.getParameter("receiver");
    final Builder named = sigreq.getUnsigned();
    //        final String username = sigreq.getUserid();
    boolean isSigned = false;
    final String objecttype = getRequestType(named);
    final String referrer = request.getHeader("Referer");
    out.write(
            "<table border=2><tr><th  colspan=\"4\" style=\"background-color:blue;color:white\">Processing: ");
    out.write(objecttype);
    out.write("</th></tr><tr><td id=\"prepare\" width=\"150\" style=\"background-color:#F0F0FF\">");
    out.write("1. Preparing ");
    out.write(objecttype);
    out.write("</td>");
    out.write("<td id=\"send\" width=\"150\" style=\"background-color:#F0F0FF\">");
    out.write("2. Sending to NeuClear Personal Trader</td>");
    out.write("<td id=\"signing\" width=\"150\"  style=\"background-color:#FFF0F0\">");
    out.write("3. Sign ");
    out.write(objecttype);
    out.write("</td>");
    out.write("<td id=\"returning\" width=\"150\">");
    out.write("4. return to site: <br/>");
    out.write(referrer);
    out.write("</td>");
    out.write("</tr></table>");

    out.flush();

    out.println("<b>Requesting Site:</b><br/>");
    out.println(referrer);
    //        out.println("</td></tr><tr><td style=\"background:lightgrey;color:black\"><tt>");
    if (isSigned)
        out.println("<h1>Signed Item:</h1>");
    else
        out.println("<h1b>Item to Sign:</h1>");

    if (named.getElement().getName().equals("AuthenticationTicket")) {
        String site = named.getElement().attributeValue("sitehref");
        String validto = named.getElement().attributeValue("validto");
        out.println("<h3>Authentication Request</h3>");
        out.println("<p>The site: <b>" + site + "</b> is requesting that you log into their web site.</p>");
    } else if (named.getElement().getName().equals("TransferOrder")) {
        String asset = named.getElement().element("Asset").getTextTrim();
        final Element recipElem = named.getElement().element("Recipient");
        String recipient = recipElem.getTextTrim();
        String recipientURL = recipElem.attributeValue("href");
        String nickname = null;
        if (!Utility.isEmpty(recipientURL)) {
            Identity recipientId = Resolver.resolveIdentity(recipientURL);
            if (!recipientId.getSignatory().getName().equals(recipient)) {
                throw new InvalidNamedObjectException("The Identity at: " + recipientURL
                        + " does not have the account number: " + recipient + " possible fraud detected");
            }
            nickname = recipientId.getNickname();
        }
        String amount = named.getElement().element("Amount").getTextTrim();
        final Element comelem = named.getElement().element("Comment");
        String comment = comelem != null ? comelem.getTextTrim() : "";
        out.println("<h3>Transfer Order</h3>");
        out.println("<p>The site: <b>" + referrer + "</b><br/> is requesting that you transfer <b>" + amount
                + "</b><br/> units of the asset <b><a href=\"" + asset + "\">" + asset
                + "</a></b><br/> to the account <b>" + recipient + "</b>");
        if (!Utility.isEmpty(recipientURL)) {
            out.print(" <a href=\"" + recipientURL + "\">" + nickname + "</a>(" + recipientURL + ")");
        }
        out.println("</p>");
        if (!Utility.isEmpty(comment)) {
            out.println("<h3>Transaction Comment:</h3>");
            out.println(comment);
        }
    }

    if (!Utility.isEmpty(sigreq.getDescription())) {
        out.println("<h3>Signature Request Comment:</h3>");
        out.println(sigreq.getDescription());
    }

    out.print(
            "<hr/><h3 onclick=\"if (message.style.display=='none')message.style.display='block'; else message.style.display='none'\">Click to toggle raw message</h3><tt id=\"message\" style=\"display:none\">");
    Matcher matcher = xmlescape.matcher(named.asXML());
    out.println(matcher.replaceAll("&lt;"));

    out.println("</tt><hr/>");
    if (isReadyToSign(request)) {

        out.println(
                "<div id=\"log\" ><tt><ol><li>Pick your Personality and enter your password in the Signer dialog window ...</li>");
        out.flush();
        try {
            isSigned = sign(named, out);
        } catch (InvalidNamedObjectException e) {
            //                System.out.println("<br><font color=\"red\"><b>ERROR: Invalid Identity</b></font><br>");
            out.println("<li><font color=\"red\"><b>ERROR: Invalid Identity</b></font></li>");
            isSigned = false;
        } catch (UserCancellationException e) {
            //                System.out.println("<br><font color=\"red\"><b>ERROR: User Cancellation</b></font><br>");
            out.println("<li><font color=\"red\"><b>You Cancelled</b></font></li>");
            out.println("<li onclick=\"history.back(2)\"><b>Click to Go back</b></li>");
            isSigned = false;
        } catch (NonExistingSignerException e) {
            //                System.out.println("<br><font color=\"red\"><b>ERROR: We Aren't Able to Sign for that Identity</b></font><br>");
            out.println(
                    "<li><font color=\"red\"><b>ERROR: We Aren't Able to Sign for that Identity</b></font></li>");
            isSigned = false;
        }
        out.print("<li>Returning to site: ");
        out.print(endpoint);
        out.println("</li></ol></tt></div>");

    }
    if (!isSigned) {
        printSecondStageForm(request, out, sigreq, endpoint);
    } else if (!Utility.isEmpty(endpoint)) {
        out.print("<form action=\"");
        out.print(Utility.denullString(receiver, endpoint));
        out.print("\" method=\"POST\"><input name=\"neuclear-request\" value=\"");
        //                    context.log("Signing Servlet: ");
        out.print(XMLSecTools.encodeElementBase64(named));
        out.println("\" type=\"hidden\"/>");
        out.write("<input name=\"endpoint\" value=\"");
        out.print(endpoint);
        out.write("\" type=\"hidden\"/>\n");

        //            out.write("<input id=\"submit\" type=\"submit\" >");
        out.write("</form>\n");
        out.write("<script language=\"javascript\">\n");
        out.write("document.forms[0].submit();\n");
        out.write("</script>\n");

    }
    out.println("</body></html>");

}

From source file:org.nuclos.server.transfer.ejb3.XmlImportFacadeBean.java

License:Open Source License

/**
 * imports a Generic Object Entity//from  ww  w  .ja  v  a  2s . c om
 *
 * @param element
 * @throws CreateException
 * @throws CommonPermissionException
 * @throws CommonCreateException
 * @throws NuclosBusinessRuleException
 */
private void importGOEntity(Element element)
        throws CommonCreateException, CommonPermissionException, NuclosBusinessRuleException {
    // Map for Attributes
    Map<Integer, DynamicAttributeVO> attributesMap = new HashMap<Integer, DynamicAttributeVO>();
    // Map for System Attributes
    Map<String, String> systemAttributes = new HashMap<String, String>();
    // Map for loaded Attribute Ids
    Set<Integer> loadattr = new HashSet<Integer>();

    Boolean bImportData = new Boolean(element.attributeValue("import"));

    // get id for the exported Module on the target system
    Integer iModuleId = modules.getModuleIdByEntityName(element.attributeValue("name"));

    String sProcessId = element.attributeValue("process");
    Integer iProcessId = (sProcessId == null || sProcessId.equals("")) ? null : new Integer(sProcessId);

    info("Import GenericObject Entity: " + element.attributeValue("name") + " ModuleId: " + iModuleId
            + " Export-Id: " + element.attribute("id").getValue());

    // Attribute Iterator
    Iterator<Element> elmit = element.elementIterator();

    try {
        // setup usage criteria
        AttributeCVO attrcvo = attributeCache.getAttribute(iModuleId,
                NuclosEOField.PROCESS.getMetaData().getField());
        DynamicAttributeVO davo = new DynamicAttributeVO(null, attrcvo.getId(), null, sProcessId);
        // put new attribute into the Map
        attributesMap.put(davo.getAttributeId(), davo);
        // put atributeId to loaded Map
        loadattr.add(attrcvo.getId());

        davo = null;
        // Iterate Attributes of the XML File
        while (elmit.hasNext()) {
            Element elem = elmit.next();
            attrcvo = attributeCache.getAttribute(iModuleId, elem.attribute("name").getText());

            debug("Import GenericObject Attribute: " + elem.attribute("name").getText());

            // fill system attribute map
            if (elem.attribute("name").getText().startsWith("[")) {
                systemAttributes.put(elem.attribute("name").getText(), elem.element("value").getTextTrim());
            }

            // attribute has references
            if (Boolean.valueOf(elem.attribute("hasReference").getText())) {
                // if attribute nuclosState set the right status model
                // reference
                if (elem.attribute("name").getText().equals(NuclosEOField.STATE.getMetaData().getField())) {
                    String sStatus = elem.element("value").getTextTrim();

                    // get new StatusId
                    Integer newStatusId = getReferenecedStatusId(iModuleId, iProcessId, sStatus);

                    // create Attribute
                    davo = new DynamicAttributeVO(null, attrcvo.getId(), newStatusId, sStatus);
                }
                // if attribute nuclosProcess
                else if (elem.attribute("name").getText()
                        .equals(NuclosEOField.PROCESS.getMetaData().getField())) {
                    davo = new DynamicAttributeVO(null, attrcvo.getId(),
                            this.getReferencedProcessId(iModuleId, elem.element("value").getTextTrim()),
                            elem.element("value").getTextTrim());

                    // common Atributes with references
                } else {
                    Boolean bIsForgeinEntityImportExportable = true;
                    String sExternalEntity = AttributeCache.getInstance()
                            .getAttribute(iModuleId, elem.attribute("name").getText()).getExternalEntity();
                    // id aus map ersetzen
                    String oldId = elem.element("referenceId").getTextTrim();
                    String newId = getMappedId(new Pair<String, String>(sExternalEntity, oldId));

                    if (Modules.getInstance().isModuleEntity(sExternalEntity)) {
                        bIsForgeinEntityImportExportable = Modules.getInstance()
                                .isImportExportable(sExternalEntity);
                    } else {
                        MasterDataMetaVO mdmvo = MasterDataMetaCache.getInstance().getMetaData(sExternalEntity);
                        bIsForgeinEntityImportExportable = (mdmvo == null) ? false : mdmvo.getIsImportExport();
                    }

                    if (newId == null && bIsForgeinEntityImportExportable) {
                        String sMessage = StringUtils.getParameterizedExceptionMessage(
                                "xmlimport.error.missing.reference.1", elem.attribute("name").getText(),
                                element.attributeValue("name"), element.attribute("id").getValue());
                        //                        "Fehler beim Ermitteln der Referenz-Id f\u00fcr das Attribut ["+elem.attribute("name").getText()+"]"+
                        //                     " der Entit\u00e4t "+element.attributeValue("name")+" mit der Id ["+element.attribute("id").getValue()+"]";
                        getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                                XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                                XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                                MessageFormat.format(
                                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                                "xmlimport.error.missing.reference.1"),
                                        elem.attribute("name").getText(), element.attributeValue("name"),
                                        element.attribute("id").getValue()),
                                iActionNumber++);

                        if (NuclosEntity.REPORT.checkEntityName(sExternalEntity)) {
                            sMessage = StringUtils.getParameterizedExceptionMessage(
                                    "xmlimport.error.missing.reference.2", elem.attribute("name").getText(),
                                    element.attributeValue("name"), element.attribute("id").getValue());
                            //" Sie besitzen kein Recht auf den referenzierten Report bzw. Formular.";
                            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                                    XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                                    MessageFormat.format(
                                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                                    "xmlimport.error.missing.reference.2"),
                                            elem.attribute("name").getText(), element.attributeValue("name"),
                                            element.attribute("id").getValue()),
                                    iActionNumber++);
                        } else {
                            sMessage = StringUtils.getParameterizedExceptionMessage(
                                    "xmlimport.error.missing.reference.3", elem.attribute("name").getText(),
                                    element.attributeValue("name"), element.attribute("id").getValue());
                            //" Evtl. wurde die Referenzierte Entit\u00e4t zuvor nicht exportiert und konnte deshalb nicht gefunden werden.";
                            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                                    XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                                    MessageFormat.format(
                                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                                    "xmlimport.error.missing.reference.3"),
                                            elem.attribute("name").getText(), element.attributeValue("name"),
                                            element.attribute("id").getValue()),
                                    iActionNumber++);
                        }

                        throw new NuclosFatalException(sMessage);
                    } else {
                        if (!bIsForgeinEntityImportExportable) {
                            newId = oldId;
                        }
                    }

                    davo = new DynamicAttributeVO(null, attrcvo.getId(), new Integer(newId),
                            elem.element("value").getTextTrim());
                }
            }
            // attributes without references
            else {
                davo = new DynamicAttributeVO(null, attrcvo.getId(), null, elem.element("value").getTextTrim());

                // check whether attribute has a value list
                if (!attrcvo.getValues().isEmpty()) {
                    Element eValueId = elem.element("valueId");
                    String sValueId = (eValueId == null) ? null : eValueId.getTextTrim();
                    if (sValueId != null && !sValueId.equals("")) {
                        davo.setValueId(new Integer(sValueId));
                    }
                }
            }
            // put new attribute into the Map
            attributesMap.put(davo.getAttributeId(), davo);
            // put atributeId to loaded Map
            loadattr.add(attrcvo.getId());
        }

        // TODO nicht generisch, complete missing system attributes
        if (!systemAttributes.containsKey(NuclosEOField.PROCESS.getMetaData().getField())) {
            attributesMap.put(
                    attributeCache.getAttribute(iModuleId, NuclosEOField.PROCESS.getMetaData().getField())
                            .getId(),
                    new DynamicAttributeVO(null, attributeCache
                            .getAttribute(iModuleId, NuclosEOField.PROCESS.getMetaData().getField()).getId(),
                            null, ""));
            loadattr.add(attributeCache.getAttribute(iModuleId, NuclosEOField.PROCESS.getMetaData().getField())
                    .getId());
        }
        if (!systemAttributes.containsKey(NuclosEOField.ORIGIN.getMetaData().getField())) {
            attributesMap.put(
                    attributeCache.getAttribute(iModuleId, NuclosEOField.ORIGIN.getMetaData().getField())
                            .getId(),
                    new DynamicAttributeVO(null, attributeCache
                            .getAttribute(iModuleId, NuclosEOField.ORIGIN.getMetaData().getField()).getId(),
                            null, ""));
            loadattr.add(attributeCache.getAttribute(iModuleId, NuclosEOField.ORIGIN.getMetaData().getField())
                    .getId());
        }

        // read parentId and deleted flag
        Integer parentId = null;
        if (!element.attributeValue("parentId").equals("null")) {
            parentId = Integer.valueOf(element.attributeValue("parentId"));
        }
        Boolean deleted = Boolean.valueOf(element.attributeValue("deleted"));

        // 1. step create NuclosValueObject with MetaData
        NuclosValueObject nvo = new NuclosValueObject(null,
                (Date) CanonicalAttributeFormat
                        .getInstance(
                                Date.class)
                        .parse(attributesMap
                                .get(AttributeCache.getInstance()
                                        .getAttribute(iModuleId,
                                                NuclosEOField.CREATEDAT.getMetaData().getField())
                                        .getId())
                                .getCanonicalValue(AttributeCache.getInstance())),
                systemAttributes.get(NuclosEOField.CREATEDBY.getMetaData().getField()),
                (Date) CanonicalAttributeFormat
                        .getInstance(
                                Date.class)
                        .parse(attributesMap
                                .get(AttributeCache.getInstance()
                                        .getAttribute(iModuleId,
                                                NuclosEOField.CHANGEDAT.getMetaData().getField())
                                        .getId())
                                .getCanonicalValue(AttributeCache.getInstance())),
                systemAttributes.get(NuclosEOField.CHANGEDBY.getMetaData().getField()), 1);

        // 2. step create GenericObjectVO
        GenericObjectVO govo = new GenericObjectVO(nvo, iModuleId, parentId, null, loadattr, deleted);
        // set attributes from attribute Map
        govo.setAttributes(attributesMap.values());

        // check if there is an existing GO with same Values in the unique
        // attributes
        GenericObjectVO existingGO = getExistingGOEntity(govo, iModuleId);

        // Entity already exists
        if (existingGO != null) {
            // modify Version and id
            nvo = new NuclosValueObject(existingGO.getId(),
                    (Date) CanonicalAttributeFormat
                            .getInstance(
                                    Date.class)
                            .parse(attributesMap
                                    .get(AttributeCache.getInstance()
                                            .getAttribute(iModuleId,
                                                    NuclosEOField.CREATEDAT.getMetaData().getField())
                                            .getId())
                                    .getCanonicalValue(AttributeCache.getInstance())),
                    //dateFormat.parse(metaAttributes.get(NuclosEOField.CREATEDAT.getMetaData().getField())),
                    systemAttributes.get(NuclosEOField.CREATEDBY.getMetaData().getField()),
                    (Date) CanonicalAttributeFormat
                            .getInstance(
                                    Date.class)
                            .parse(attributesMap
                                    .get(AttributeCache.getInstance()
                                            .getAttribute(iModuleId,
                                                    NuclosEOField.CHANGEDAT.getMetaData().getField())
                                            .getId())
                                    .getCanonicalValue(AttributeCache.getInstance())),
                    //dateFormat.parse(metaAttributes.get(NuclosEOField.CHANGEDAT.getMetaData().getField())),
                    systemAttributes.get(NuclosEOField.CHANGEDBY.getMetaData().getField()),
                    existingGO.getVersion());

            Collection<DynamicAttributeVO> exattr = existingGO.getAttributes();

            // replace attribute values
            for (DynamicAttributeVO dynattr : exattr) {
                if (attributesMap.containsKey(dynattr.getAttributeId())) {
                    DynamicAttributeVO mapvalue = attributesMap.get(dynattr.getAttributeId());
                    dynattr.setCanonicalValue(mapvalue.getCanonicalValue(attributeCache), attributeCache);
                    if (mapvalue.getValueId() != null) {
                        dynattr.setValueId(mapvalue.getValueId());
                    }
                    attributesMap.remove(dynattr.getAttributeId());
                } else {
                    dynattr.remove();
                }
            }

            govo = new GenericObjectVO(nvo, iModuleId, parentId, null, loadattr, deleted);

            // set existing attributes with new values
            govo.setAttributes(exattr);
            // set new attributes
            for (DynamicAttributeVO dynattr : attributesMap.values()) {
                govo.setAttribute(dynattr);
            }

            // read all subforms of all layouts
            if (!mpGoSubFormsWithForeignKeys.containsKey(govo.getModuleId())) {
                List<Map<EntityAndFieldName, String>> lseafn = new ArrayList<Map<EntityAndFieldName, String>>();
                for (Integer iLayoutId : genericObjectMetaDataCache.getLayoutIdsByModuleId(govo.getModuleId(),
                        false)) {
                    LayoutFacadeLocal layoutFacade = ServerServiceLocator.getInstance()
                            .getFacade(LayoutFacadeLocal.class);
                    Map<EntityAndFieldName, String> subformtree = layoutFacade
                            .getSubFormEntityAndParentSubFormEntityNamesByLayoutId(iLayoutId);
                    Map<EntityAndFieldName, String> subformtree_with_fkeys = new HashMap<EntityAndFieldName, String>();
                    for (EntityAndFieldName eafn : subformtree.keySet()) {
                        String sParentEntity = element.attributeValue("name");
                        if (subformtree.get(eafn) != null) {
                            sParentEntity = subformtree.get(eafn);
                        }

                        String s1 = eafn.getEntityName();
                        String sForeignKeyFieldName = XmlExportImportHelper.getForeignKeyFieldName(
                                sParentEntity, eafn.getFieldName(), eafn.getEntityName());
                        subformtree_with_fkeys.put(new EntityAndFieldName(s1, sForeignKeyFieldName),
                                subformtree.get(eafn));
                    }
                    lseafn.add(subformtree_with_fkeys);
                }
                mpGoSubFormsWithForeignKeys.put(govo.getModuleId(), lseafn);
            }

            // if data was "imported" remove all dependant data, because the dependant data were exported as well
            if (bImportData) {
                for (Map<EntityAndFieldName, String> mpSubFormsWithForeignKeys : mpGoSubFormsWithForeignKeys
                        .get(govo.getModuleId())) {
                    readDependants(mpSubFormsWithForeignKeys, null, existingGO.getId(),
                            new DependantMasterDataMapImpl());
                }
            }

            // call modify Method
            String sMessage;// = StringUtils.getParameterizedExceptionMessage("xmlimport.error.module.entity.1", element.attribute("name").getValue(), existingGO.getId());
            //"Modul-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der ID ["+existingGO.getId()+"] ";
            String sAction = XmlExportImportHelper.EXPIMP_ACTION_UPDATE;
            if (bImportData) {
                GenericObjectWithDependantsVO modifiedGO = getGenericObjectFacade().modify(iModuleId,
                        new GenericObjectWithDependantsVO(govo, null), ServerParameterProvider.getInstance()
                                .getValue(ParameterProvider.KEY_LAYOUT_CUSTOM_KEY));

                if ((modifiedGO.getId()).compareTo(existingGO.getId()) != 0) {
                    sMessage = StringUtils.getParameterizedExceptionMessage("xmlimport.error.module.entity.2",
                            element.attribute("name").getValue(), existingGO.getId());
                    //"konnte nicht im Zielsystem ermittelt werden.";
                    getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                            XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR, sAction,
                            MessageFormat.format(
                                    localeFacade.getResourceById(localeFacade.getUserLocale(),
                                            "xmlimport.error.module.entity.2"),
                                    element.attribute("name").getValue(), existingGO.getId()),
                            iActionNumber++);
                    throw new NuclosFatalException(sMessage);
                } else {
                    sMessage = MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.module.entity.3"),
                            element.attribute("name").getValue(), existingGO.getId());
                    //"erfolgreich ge\u00e4ndert.";
                    info(sMessage);
                    getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                            XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO, sAction, sMessage,
                            iActionNumber++);
                }
            } else {
                sAction = XmlExportImportHelper.EXPIMP_ACTION_READ;
                sMessage = MessageFormat.format(
                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                "xmlimport.error.module.entity.4"),
                        element.attribute("name").getValue(), existingGO.getId());
                //"erfolgreich im Zielsystem ermittelt.";
                info(sMessage);
                getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                        XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO, sAction, sMessage, iActionNumber++);
            }

            // create old/new Id matching
            idMap.put(new Pair<String, String>(element.attribute("name").getValue(),
                    element.attribute("id").getValue()), String.valueOf(existingGO.getId()));
            // remember all imported genericobjects
            lstAllImportedEntityIds
                    .add(new Pair<String, Integer>(element.attributeValue("name"), existingGO.getId()));

            //            info(sMessage);
            //            getProtocolFacade().writeExportImportLogEntry(iProtocolId, XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO,
            //                  sAction, sMessage, iActionNumber++);
        }
        // Entity not exists
        else {
            // create new GO
            if (bImportData) {
                GenericObjectVO newGoVO = getGenericObjectFacade().create(
                        new GenericObjectWithDependantsVO(govo, new DependantMasterDataMapImpl()), null);

                // create old/new Id matching
                idMap.put(new Pair<String, String>(element.attributeValue("name"),
                        element.attribute("id").getValue()), String.valueOf(newGoVO.getId()));
                // remember all imported genericobjects
                lstAllImportedEntityIds
                        .add(new Pair<String, Integer>(element.attributeValue("name"), newGoVO.getId()));

                String sMessage = MessageFormat.format(
                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                "xmlimport.error.module.entity.1"),
                        element.attribute("name").getValue(), newGoVO.getId());
                //"Modul-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der ID ["+newGoVO.getId()+"] erfolgreich angelegt.";
                info(sMessage);
                getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                        XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO,
                        XmlExportImportHelper.EXPIMP_ACTION_INSERT, sMessage, iActionNumber++);
            }
        }
    } catch (Exception e) {
        String sMessage = StringUtils.getParameterizedExceptionMessage("xmlimport.error.module.entity.5",
                element.attribute("name").getValue(), element.attribute("id").getValue(), e);
        //"Modul-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der Export-ID ["+element.attribute("id").getValue()+"] konnte nicht angelegt werden. "+e;
        getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR, XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                MessageFormat.format(
                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                "xmlimport.error.module.entity.5"),
                        element.attribute("name").getValue(), element.attribute("id").getValue(), e),
                iActionNumber++);
        throw new NuclosFatalException(sMessage);
    }
}

From source file:org.nuclos.server.transfer.ejb3.XmlImportFacadeBean.java

License:Open Source License

/**
 * imports a MasterData Entity//from  w  ww  . j a  v a 2  s.  c o m
 *
 * @param element
 *            node of the exportet Entity in the xml file
 * @throws CreateException
 * @throws CommonPermissionException
 * @throws CommonCreateException
 * @throws CommonFinderException
 * @throws ElisaBusinessException
 */
private void importMDEntity(Element element) throws CommonCreateException, CommonPermissionException,
        NuclosBusinessException, CommonFinderException {
    info("Import MasterData Entity: " + element.attributeValue("name") + " Export-Id: "
            + element.attribute("id").getValue());

    final Boolean bImportData = new Boolean(element.attributeValue("import"));
    final String sEntityName = element.attribute("name").getValue();

    // fetch metadata
    MasterDataMetaVO mdm = getMasterDataFacade().getMetaData(sEntityName);
    List<MasterDataMetaFieldVO> metafields = mdm.getFields();

    // Map for MD values
    Map<String, Object> mpFields = new HashMap<String, Object>();
    // Map for additional system Attributes like created_by, changed_at, version ...
    Map<String, String> metaAttributes = new HashMap<String, String>();

    // iterates the MD Meta fields and fills the Master Data Value Map
    Iterator<MasterDataMetaFieldVO> fieldIt = metafields.iterator();
    MasterDataMetaFieldVO mfield;
    while (fieldIt.hasNext()) {
        mfield = fieldIt.next();

        debug("Import MasterDataField: " + mfield.getFieldName());

        try {
            // if Field with Reference
            if (mfield.getForeignEntity() != null) {
                Element elm = element.element(mfield.getFieldName() + "Id");
                if (elm != null) {
                    String oldId = elm.getTextTrim();

                    if (oldId != null && !oldId.equals("")) {
                        Boolean bIsForgeinEntityImportExportable = true;
                        String sForeignEntity = mfield.getForeignEntity();

                        assert !StringUtils.isNullOrEmpty(sForeignEntity);

                        if (Modules.getInstance().isModuleEntity(sForeignEntity)) {
                            bIsForgeinEntityImportExportable = Modules.getInstance()
                                    .isImportExportable(sForeignEntity);
                        } else {
                            MasterDataMetaVO mdmvo = MasterDataMetaCache.getInstance()
                                    .getMetaData(sForeignEntity);
                            bIsForgeinEntityImportExportable = (mdmvo == null) ? false
                                    : mdmvo.getIsImportExport();
                        }

                        // match old to new Id
                        Object newId = null;
                        // special handling for entity genericobjectrelation, because the foreignkey entity is set to generalsearch
                        // for the fields source and destination and therefore it's not possible to determine the corresponding object ids
                        //                     if ("genericobjectrelation".equals(element.attributeValue("name")) &&
                        //                           (mfield.getFieldName().equals("source") || mfield.getFieldName().equals("destination"))) {
                        if ("generalSearch".equalsIgnoreCase(sForeignEntity)) {
                            bIsForgeinEntityImportExportable = true;
                            newId = getMappedId(oldId);
                        } else {
                            newId = getMappedId(new Pair<String, String>(sForeignEntity, oldId));
                        }

                        if (newId == null && bIsForgeinEntityImportExportable) {
                            String sMessage;
                            //                           "Fehler beim Ermitteln der Referenz-Id f\u00fcr das Feld ["+mfield.getFieldName()+"]"+
                            //                        " der Entit\u00e4t "+element.attributeValue("name")+" mit der Id ["+element.attribute("id").getValue()+"]";

                            if (NuclosEntity.REPORT.checkEntityName(sForeignEntity)) {
                                sMessage = StringUtils.getParameterizedExceptionMessage(
                                        "xmlimport.error.missing.mdreference.2", mfield.getFieldName(),
                                        element.attributeValue("name"), element.attribute("id").getValue());
                                //" Sie besitzen kein Recht auf den referenzierten Report bzw. Formular.";
                                getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                                        XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                                        XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                                        MessageFormat.format(
                                                localeFacade.getResourceById(localeFacade.getUserLocale(),
                                                        "xmlimport.error.missing.mdreference.2"),
                                                mfield.getFieldName(), element.attributeValue("name"),
                                                element.attribute("id").getValue()),
                                        iActionNumber++);
                            } else {
                                sMessage = StringUtils.getParameterizedExceptionMessage(
                                        "xmlimport.error.missing.mdreference.3", mfield.getFieldName(),
                                        element.attributeValue("name"), element.attribute("id").getValue());
                                //" Evtl. wurde die Referenzierte Entit\u00e4t zuvor nicht exportiert und konnte deshalb nicht gefunden werden.";
                                getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                                        XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                                        XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                                        MessageFormat.format(
                                                localeFacade.getResourceById(localeFacade.getUserLocale(),
                                                        "xmlimport.error.missing.mdreference.3"),
                                                mfield.getFieldName(), element.attributeValue("name"),
                                                element.attribute("id").getValue()),
                                        iActionNumber++);
                            }
                            //                        getProtocolFacade().writeExportImportLogEntry(iProtocolId, XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                            //                              XmlExportImportHelper.EXPIMP_ACTION_INSERT, sMessage, iActionNumber++);
                            throw new NuclosFatalException(sMessage);
                        } else {
                            if (!bIsForgeinEntityImportExportable) {
                                newId = oldId;
                            }
                        }
                        mpFields.put(mfield.getFieldName() + "Id", Integer.parseInt(newId.toString()));
                    }
                }
            }
            // if field without a Reference
            else {
                Element elm = element.element(mfield.getFieldName());
                if (elm != null) {
                    String selmText = elm.getText();
                    if (!"".equals(selmText)) {
                        putFieldToMap(mpFields, mfield, selmText, element);
                    }
                }
            }
        } catch (ParseException e) {
            String sMessage = StringUtils.getParameterizedExceptionMessage("xmlimport.error.parse.value",
                    element.attribute("name").getValue(), element.attribute("id").getValue(), e);
            //               "Fehler beim Parsen eines Wertes der zu importierenden Datei bei der Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] " +
            //            "mit der Export-ID ["+element.attribute("id").getValue()+"]. "+e;
            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                    XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                    MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.parse.value"),
                            element.attribute("name").getValue(), element.attribute("id").getValue(), e),
                    iActionNumber++);
            throw new NuclosFatalException(sMessage);
        } catch (IOException e) {
            String sMessage = StringUtils.getParameterizedExceptionMessage("xmlimport.error.read.file",
                    element.attribute("name").getValue(), element.attribute("id").getValue(), e);
            //               "Fehler beim lesen einer zu importierenden Datei bei der Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] " +
            //            "mit der Export-ID ["+element.attribute("id").getValue()+"]. "+e;
            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                    XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                    MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.read.file"),
                            element.attribute("name").getValue(), element.attribute("id").getValue(), e),
                    iActionNumber++);
            throw new NuclosFatalException(sMessage);
        } catch (ClassNotFoundException e) {
            String sMessage = StringUtils.getParameterizedExceptionMessage("xmlimport.error.read.object",
                    element.attribute("name").getValue(), element.attribute("id").getValue(), e);
            //               "Fehler beim lesen eines zu importierenden Objekts der Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] " +
            //            "mit der Export-ID ["+element.attribute("id").getValue()+"]. "+e;
            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                    XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                    MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.read.object"),
                            element.attribute("name").getValue(), element.attribute("id").getValue(), e),
                    iActionNumber++);
            throw new NuclosFatalException(sMessage);
        } catch (Exception e) {
            throw new NuclosFatalException(e);
        }
    }

    // fill MD additional System attributes like created_by, changed_at
    Iterator<Element> i2 = element.elementIterator();
    while (i2.hasNext()) {
        Element field = i2.next();
        if (field.getName().equals("attribute")) {
            metaAttributes.put(field.attributeValue("name"), field.getTextTrim());
        }
    }

    // prepare new MD Record
    MasterDataVO prepVO;
    try {
        String sCreatedAt = metaAttributes.get(NuclosEOField.CREATEDAT.getMetaData().getField());
        String sCreatedBy = metaAttributes.get(NuclosEOField.CREATEDBY.getMetaData().getField());
        String sChangedAt = metaAttributes.get(NuclosEOField.CHANGEDAT.getMetaData().getField());
        String sChangedBy = metaAttributes.get(NuclosEOField.CHANGEDBY.getMetaData().getField());

        String sNow = DateUtils.toString(DateUtils.now()) + " 00:00:00";

        prepVO = new MasterDataVO(sEntityName, null, dateFormat.parse((sCreatedAt == null) ? sNow : sCreatedAt),
                (sCreatedBy == null) ? "INITIAL" : sCreatedBy,
                dateFormat.parse((sChangedAt == null) ? sNow : sChangedAt),
                (sChangedBy == null) ? "INITIAL" : sChangedBy, 1, mpFields);
    } catch (ParseException e) {
        String sMessage = StringUtils.getParameterizedExceptionMessage("xmlimport.error.parse.date",
                element.attribute("name").getValue(), element.attribute("id").getValue(), e);
        //            "Fehler beim Parsen des Datums bei der Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] " +
        //            "mit der Export-ID ["+element.attribute("id").getValue()+"]. "+e;
        getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR, XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                MessageFormat.format(
                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                "xmlimport.error.parse.date"),
                        element.attribute("name").getValue(), element.attribute("id").getValue(), e),
                iActionNumber++);
        throw new NuclosFatalException(sMessage);
    }

    // check if Entity already exists
    MasterDataVO existingEntity = getExistingMDEntity(prepVO, element.attribute("name").getValue());

    if (existingEntity != null) {
        // entity exists
        try {
            // set old id and old version
            prepVO = new MasterDataVO(sEntityName, existingEntity.getId(), prepVO.getCreatedAt(),
                    prepVO.getCreatedBy(), prepVO.getChangedAt(), prepVO.getChangedBy(),
                    existingEntity.getVersion(), prepVO.getFields());

            // read all dependant data
            DependantMasterDataMap dmdm = null;

            if (!mpMdSubFormsWithForeignKeys.containsKey(sEntityName)) {
                LayoutFacadeLocal layoutFacade = ServerServiceLocator.getInstance()
                        .getFacade(LayoutFacadeLocal.class);
                mpMdSubFormsWithForeignKeys.put(sEntityName,
                        layoutFacade.getSubFormEntityAndParentSubFormEntityNames(sEntityName, prepVO.getIntId(),
                                true, ServerParameterProvider.getInstance()
                                        .getValue(ParameterProvider.KEY_LAYOUT_CUSTOM_KEY)));
            }

            // if data was "imported" remove all dependant data, because the dependant data were exported as well
            if (bImportData) {
                readDependants(mpMdSubFormsWithForeignKeys.get(sEntityName), null, existingEntity.getIntId(),
                        new DependantMasterDataMapImpl());
            }

            // call modify Method
            String sMessage;// = "Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der ID ["+existingEntity.getId()+"] ";
            String sAction = XmlExportImportHelper.EXPIMP_ACTION_UPDATE;
            if (bImportData) {
                Object modid = getMasterDataFacade().modify(element.attribute("name").getValue(), prepVO, dmdm,
                        null);

                if (((Integer) modid).compareTo((Integer) existingEntity.getId()) != 0) {
                    sMessage = StringUtils.getParameterizedExceptionMessage(
                            "xmlimport.error.masterdata.entity.2", element.attribute("name").getValue(),
                            existingEntity.getId());
                    //"konnte nicht im Zielsystem ermittelt werden.";
                    getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                            XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR, sAction,
                            MessageFormat.format(
                                    localeFacade.getResourceById(localeFacade.getUserLocale(),
                                            "xmlimport.error.masterdata.entity.2"),
                                    element.attribute("name").getValue(), existingEntity.getId()),
                            iActionNumber++);
                    throw new NuclosFatalException(sMessage);
                } else {
                    sMessage = MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.masterdata.entity.3"),
                            element.attribute("name").getValue(), existingEntity.getId());
                    //"erfolgreich ge\u00e4ndert.";
                    info(sMessage);
                    getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                            XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO, sAction, sMessage,
                            iActionNumber++);
                }
            } else {
                sAction = XmlExportImportHelper.EXPIMP_ACTION_READ;
                sMessage = MessageFormat.format(
                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                "xmlimport.error.masterdata.entity.4"),
                        element.attribute("name").getValue(), existingEntity.getId());
                //"erfolgreich im Zielsystem ermittelt.";
                info(sMessage);
                getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                        XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO, sAction, sMessage, iActionNumber++);
            }

            // create old/new Id matching
            idMap.put(new Pair<String, String>(element.attribute("name").getValue(),
                    element.attribute("id").getValue()), String.valueOf(existingEntity.getId()));
            // remember all imported masterdata
            lstAllImportedEntityIds.add(new Pair<String, Integer>(element.attribute("name").getValue(),
                    (Integer) existingEntity.getId()));

            //            info(sMessage);
            //            getProtocolFacade().writeExportImportLogEntry(iProtocolId, XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO,
            //                  sAction, sMessage, iActionNumber++);
        } catch (Exception e) {
            String sMessage = StringUtils.getParameterizedExceptionMessage(
                    "xmlimport.error.masterdata.entity.5", element.attribute("name").getValue(),
                    element.attribute("id"), e);
            //"Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der Export-ID ["+element.attribute("id")+"] konnte nicht modifiziert werden. "+e;
            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                    XmlExportImportHelper.EXPIMP_ACTION_UPDATE,
                    MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.masterdata.entity.5"),
                            element.attribute("name").getValue(), element.attribute("id"), e),
                    iActionNumber++);
            throw new NuclosFatalException(sMessage);
        }
    } else {
        // entity not exists
        try {
            if (bImportData) {
                // call create Method
                MasterDataVO newVO = getMasterDataFacade().create(element.attribute("name").getValue(), prepVO,
                        null, null);

                // create old/new Id matching
                idMap.put(new Pair<String, String>(element.attribute("name").getValue(),
                        element.attribute("id").getValue()), String.valueOf(newVO.getId()));
                // remember all imported masterdata
                lstAllImportedEntityIds
                        .add(new Pair<String, Integer>(element.attribute("name").getValue(), newVO.getIntId()));

                String sMessage = MessageFormat.format(
                        localeFacade.getResourceById(localeFacade.getUserLocale(),
                                "xmlimport.error.masterdata.entity.6"),
                        element.attribute("name").getValue(), newVO.getIntId());
                //"Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der ID ["+newVO.getIntId()+"] erfolgreich angelegt.";
                info(sMessage);
                getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                        XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_INFO,
                        XmlExportImportHelper.EXPIMP_ACTION_INSERT, sMessage, iActionNumber++);
            }
        } catch (Exception e) {
            String sMessage = StringUtils.getParameterizedExceptionMessage(
                    "xmlimport.error.masterdata.entity.7", element.attribute("name").getValue(),
                    element.attribute("id"), e);
            //"Stammdaten-Entit\u00e4t ["+element.attribute("name").getValue()+"] mit der Export-ID ["+element.attribute("id")+"] konnte nicht angelegt werden. "+e;
            getProtocolFacade().writeExportImportLogEntry(iProtocolId,
                    XmlExportImportHelper.EXPIMP_MESSAGE_LEVEL_ERROR,
                    XmlExportImportHelper.EXPIMP_ACTION_INSERT,
                    MessageFormat.format(
                            localeFacade.getResourceById(localeFacade.getUserLocale(),
                                    "xmlimport.error.masterdata.entity.7"),
                            element.attribute("name").getValue(), element.attribute("id"), e),
                    iActionNumber++);
            throw new NuclosFatalException(sMessage);
        }
    }
}

From source file:org.nuxeo.ecm.core.io.impl.AbstractDocumentModelWriter.java

License:Apache License

@SuppressWarnings("unchecked")
protected boolean loadFacetsInfo(DocumentModel docModel, Document doc) {
    boolean added = false;
    Element system = doc.getRootElement().element(ExportConstants.SYSTEM_TAG);
    if (system == null) {
        return false;
    }/*w  w  w . j a v a2s .  co  m*/

    Iterator<Element> facets = system.elementIterator(ExportConstants.FACET_TAG);
    while (facets.hasNext()) {
        Element element = facets.next();
        String facet = element.getTextTrim();

        SchemaManager schemaManager = Framework.getService(SchemaManager.class);
        CompositeType facetType = schemaManager.getFacet(facet);

        if (facetType == null) {
            log.warn("The document " + docModel.getName() + " with id=" + docModel.getId() + " and type="
                    + docModel.getDocumentType().getName() + " contains the facet '" + facet
                    + "', which is not registered as available in the schemaManager. This facet will be ignored.");
            if (log.isDebugEnabled()) {
                log.debug("Available facets: " + Arrays.toString(schemaManager.getFacets()));
            }
            continue;
        }

        if (!docModel.hasFacet(facet)) {
            docModel.addFacet(facet);
            added = true;
        }
    }

    return added;
}

From source file:org.nuxeo.ecm.platform.ui.web.rest.StaticNavigationHandler.java

License:Apache License

/**
 * @since 5.6/*from w ww.j  a  v  a  2 s  .  c  om*/
 */
@SuppressWarnings("unchecked")
protected void parse(InputStream stream) {
    Element root = getDocumentRoot(stream);
    List<Element> elements = root.elements("navigation-rule");
    for (Element rule : elements) {
        List<Element> nav_cases = rule.elements("navigation-case");
        for (Element nav_case : nav_cases) {
            Element from_el = nav_case.element("from-outcome");
            Element to_el = nav_case.element("to-view-id");

            if ((from_el != null) && (to_el != null)) {
                String from = from_el.getTextTrim();
                String to = to_el.getTextTrim();
                outcomeToViewId.put(from, to);
                viewIdToOutcome.put(to, from);
            }
        }
    }
}