Example usage for org.apache.commons.lang3 StringUtils isNoneEmpty

List of usage examples for org.apache.commons.lang3 StringUtils isNoneEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isNoneEmpty.

Prototype

public static boolean isNoneEmpty(final CharSequence... css) 

Source Link

Document

Checks if none of the CharSequences are empty ("") or null.

 StringUtils.isNoneEmpty(null)             = false StringUtils.isNoneEmpty(null, "foo")      = false StringUtils.isNoneEmpty("", "bar")        = false StringUtils.isNoneEmpty("bob", "")        = false StringUtils.isNoneEmpty("  bob  ", null)  = false StringUtils.isNoneEmpty(" ", "bar")       = true StringUtils.isNoneEmpty("foo", "bar")     = true 

Usage

From source file:org.craftercms.studio.impl.v1.web.security.access.StudioPublishingAPIAccessDecisionVoter.java

@Override
public int vote(Authentication authentication, Object o, Collection collection) {
    int toRet = ACCESS_ABSTAIN;
    String requestUri = "";
    if (o instanceof FilterInvocation) {
        FilterInvocation filterInvocation = (FilterInvocation) o;
        HttpServletRequest request = filterInvocation.getRequest();
        requestUri = request.getRequestURI().replace(request.getContextPath(), "");
        String userParam = request.getParameter("username");
        String siteParam = request.getParameter("site_id");
        if (StringUtils.isEmpty(userParam)
                && StringUtils.equalsIgnoreCase(request.getMethod(), HttpMethod.POST.name())
                && !ServletFileUpload.isMultipartContent(request)) {
            try {
                InputStream is = request.getInputStream();
                is.mark(0);/*from w  w w .  j a v  a2s.co m*/
                String jsonString = IOUtils.toString(is);
                if (StringUtils.isNoneEmpty(jsonString)) {
                    JSONObject jsonObject = JSONObject.fromObject(jsonString);
                    if (jsonObject.has("username")) {
                        userParam = jsonObject.getString("username");
                    }
                    if (jsonObject.has("site_id")) {
                        siteParam = jsonObject.getString("site_id");
                    }
                }
                is.reset();
            } catch (IOException | JSONException e) {
                // TODO: ??
                logger.debug("Failed to extract username from POST request");
            }
        }
        User currentUser = null;
        try {
            currentUser = (User) authentication.getPrincipal();
        } catch (ClassCastException e) {
            // anonymous user
            if (!authentication.getPrincipal().toString().equals("anonymousUser")) {
                logger.info("Error getting current user", e);
                return ACCESS_ABSTAIN;
            }
        }
        switch (requestUri) {
        case START:
        case STOP:
            if (currentUser != null) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        case STATUS:
            if (siteService.exists(siteParam)) {
                if (currentUser != null && isSiteMember(siteParam, currentUser)) {
                    toRet = ACCESS_GRANTED;
                } else {
                    toRet = ACCESS_DENIED;
                }
            } else {
                toRet = ACCESS_ABSTAIN;
            }
            break;
        default:
            toRet = ACCESS_ABSTAIN;
            break;
        }
    }
    logger.debug("Request: " + requestUri + " - Access: " + toRet);
    return toRet;
}

From source file:org.craftercms.studio.impl.v1.web.security.access.StudioSiteAPIAccessDecisionVoter.java

@Override
public int vote(Authentication authentication, Object o, Collection collection) {
    int toRet = ACCESS_ABSTAIN;
    String requestUri = "";
    if (o instanceof FilterInvocation) {
        FilterInvocation filterInvocation = (FilterInvocation) o;
        HttpServletRequest request = filterInvocation.getRequest();
        requestUri = request.getRequestURI().replace(request.getContextPath(), "");
        String userParam = request.getParameter("username");
        if (StringUtils.isEmpty(userParam)
                && StringUtils.equalsIgnoreCase(request.getMethod(), HttpMethod.POST.name())
                && !ServletFileUpload.isMultipartContent(request)) {
            try {
                InputStream is = request.getInputStream();
                is.mark(0);//w ww  .  j  a  v  a2  s  .c o  m
                String jsonString = IOUtils.toString(is);
                if (StringUtils.isNoneEmpty(jsonString)) {
                    JSONObject jsonObject = JSONObject.fromObject(jsonString);
                    if (jsonObject.has("username")) {
                        userParam = jsonObject.getString("username");
                    }
                }
                is.reset();
            } catch (IOException | JSONException e) {
                // TODO: ??
                logger.debug("Failed to extract username from POST request");
            }
        }
        User currentUser = null;
        try {
            currentUser = (User) authentication.getPrincipal();
        } catch (ClassCastException e) {
            // anonymous user
            if (!authentication.getPrincipal().toString().equals("anonymousUser")) {
                logger.info("Error getting current user", e);
                return ACCESS_ABSTAIN;
            }
        }
        switch (requestUri) {
        case CREATE:
        case DELETE:
            if (currentUser != null && isAdmin(currentUser)) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        default:
            toRet = ACCESS_ABSTAIN;
            break;
        }
    }
    logger.debug("Request: " + requestUri + " - Access: " + toRet);
    return toRet;
}

From source file:org.craftercms.studio.impl.v1.web.security.access.StudioUserAPIAccessDecisionVoter.java

@Override
public int vote(Authentication authentication, Object o, Collection collection) {
    int toRet = ACCESS_ABSTAIN;
    String requestUri = "";
    if (o instanceof FilterInvocation) {
        FilterInvocation filterInvocation = (FilterInvocation) o;
        HttpServletRequest request = filterInvocation.getRequest();
        requestUri = request.getRequestURI().replace(request.getContextPath(), "");
        String userParam = request.getParameter("username");
        String siteParam = request.getParameter("site_id");
        if (StringUtils.isEmpty(userParam)
                && StringUtils.equalsIgnoreCase(request.getMethod(), HttpMethod.POST.name())
                && !ServletFileUpload.isMultipartContent(request)) {
            try {
                InputStream is = request.getInputStream();
                is.mark(0);/*from   w w w.  j a  v a 2  s  .  c om*/
                String jsonString = IOUtils.toString(is);
                if (StringUtils.isNoneEmpty(jsonString)) {
                    JSONObject jsonObject = JSONObject.fromObject(jsonString);
                    if (jsonObject.has("username")) {
                        userParam = jsonObject.getString("username");
                    }
                    if (jsonObject.has("site_id")) {
                        siteParam = jsonObject.getString("site_id");
                    }
                }
                is.reset();
            } catch (IOException | JSONException e) {
                // TODO: ??
                logger.debug("Failed to extract username from POST request");
            }
        }
        User currentUser = null;
        try {
            currentUser = (User) authentication.getPrincipal();
        } catch (ClassCastException e) {
            // anonymous user
            if (!authentication.getPrincipal().toString().equals("anonymousUser")) {
                logger.info("Error getting current user", e);
                return ACCESS_ABSTAIN;
            }
        }
        switch (requestUri) {
        case FORGOT_PASSWORD:
        case LOGIN:
        case LOGOUT:
        case SET_PASSWORD:
        case VALIDATE_TOKEN:
            toRet = ACCESS_GRANTED;
            break;
        case CHANGE_PASSWORD:
            if (currentUser != null && isSelf(currentUser, userParam)) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        case CREATE:
        case DELETE:
        case DISABLE:
        case ENABLE:
        case RESET_PASSWORD:
        case STATUS:
            if (currentUser != null && isAdmin(currentUser)) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        case GET_ALL:
            if (currentUser != null) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        case GET:
            if (currentUser != null && (isAdmin(currentUser) || isSelf(currentUser, userParam)
                    || isSiteMember(currentUser, userParam))) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        case GET_PER_SITE:
            if (currentUser != null && (isAdmin(currentUser) || isSiteMember(currentUser, userParam))) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        case UPDATE:
            if (currentUser != null && (isAdmin(currentUser) || isSelf(currentUser, userParam))) {
                toRet = ACCESS_GRANTED;
            } else {
                toRet = ACCESS_DENIED;
            }
            break;
        default:
            toRet = ACCESS_ABSTAIN;
            break;
        }
    }
    logger.debug("Request: " + requestUri + " - Access: " + toRet);
    return toRet;
}

From source file:org.efaps.admin.index.Indexer.java

/**
 * Index or reindex a given list of instances. The given instances m,ust be
 * all of the same type!/*from  w  ww .  ja va  2  s . c o m*/
 *
 * @param _context the _context
 * @param _instances the instances
 * @throws EFapsException the e faps exception
 */
public static void index(final IndexContext _context, final List<Instance> _instances) throws EFapsException {
    if (CollectionUtils.isNotEmpty(_instances)) {
        final Company currentCompany = Context.getThreadContext().getCompany();
        final String currentLanguage = Context.getThreadContext().getLanguage();

        Context.getThreadContext().setCompany(Company.get(_context.getCompanyId()));
        Context.getThreadContext().setLanguage(_context.getLanguage());
        final IndexWriterConfig config = new IndexWriterConfig(_context.getAnalyzer());
        try (IndexWriter writer = new IndexWriter(_context.getDirectory(), config);
                TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(_context.getTaxonomyDirectory());) {

            final IndexDefinition def = IndexDefinition.get(_instances.get(0).getType().getUUID());
            final MultiPrintQuery multi = new MultiPrintQuery(_instances);
            for (final IndexField field : def.getFields()) {
                multi.addSelect(field.getSelect());
            }
            Attribute createdAttr = null;
            if (!_instances.get(0).getType().getAttributes(CreatedType.class).isEmpty()) {
                createdAttr = _instances.get(0).getType().getAttributes(CreatedType.class).iterator().next();
                multi.addAttribute(createdAttr);
            }
            multi.addMsgPhrase(def.getMsgPhrase());
            multi.executeWithoutAccessCheck();
            while (multi.next()) {
                final String oid = multi.getCurrentInstance().getOid();
                final String type = multi.getCurrentInstance().getType().getLabel();
                final DateTime created;
                if (createdAttr == null) {
                    created = new DateTime();
                } else {
                    created = multi.getAttribute(createdAttr);
                }

                final Document doc = new Document();
                doc.add(new FacetField(Dimension.DIMTYPE.name(), type));
                doc.add(new FacetField(Dimension.DIMCREATED.name(), String.valueOf(created.getYear()),
                        String.format("%02d", created.getMonthOfYear())));
                doc.add(new StringField(Key.OID.name(), oid, Store.YES));
                doc.add(new TextField(DBProperties.getProperty("index.Type"), type, Store.YES));
                doc.add(new NumericDocValuesField(Key.CREATED.name(), created.getMillis()));
                doc.add(new StringField(Key.CREATEDSTR.name(),
                        DateTools.dateToString(created.toDate(), DateTools.Resolution.DAY), Store.NO));

                final StringBuilder allBldr = new StringBuilder().append(type).append(" ");

                for (final IndexField field : def.getFields()) {
                    final String name = DBProperties.getProperty(field.getKey());
                    Object value = multi.getSelect(field.getSelect());
                    if (value != null) {
                        if (StringUtils.isNoneEmpty(field.getTransform())) {
                            final Class<?> clazz = Class.forName(field.getTransform(), false,
                                    EFapsClassLoader.getInstance());
                            final ITransformer transformer = (ITransformer) clazz.newInstance();
                            value = transformer.transform(value);
                        }
                        switch (field.getFieldType()) {
                        case LONG:
                            long val = 0;
                            if (value instanceof String) {
                                val = NumberUtils.toLong((String) value);
                            } else if (value instanceof Number) {
                                val = ((Number) value).longValue();
                            }
                            doc.add(new LongField(name, val, Store.YES));
                            allBldr.append(value).append(" ");
                            break;
                        case SEARCHLONG:
                            long val2 = 0;
                            if (value instanceof String) {
                                val2 = NumberUtils.toLong((String) value);
                            } else if (value instanceof Number) {
                                val2 = ((Number) value).longValue();
                            }
                            doc.add(new LongField(name, val2, Store.NO));
                            allBldr.append(value).append(" ");
                            break;
                        case STRING:
                            doc.add(new StringField(name, String.valueOf(value), Store.YES));
                            allBldr.append(value).append(" ");
                            break;
                        case SEARCHSTRING:
                            doc.add(new StringField(name, String.valueOf(value), Store.NO));
                            allBldr.append(value).append(" ");
                            break;
                        case TEXT:
                            doc.add(new TextField(name, String.valueOf(value), Store.YES));
                            allBldr.append(value).append(" ");
                            break;
                        case SEARCHTEXT:
                            doc.add(new TextField(name, String.valueOf(value), Store.NO));
                            allBldr.append(value).append(" ");
                            break;
                        case STORED:
                            doc.add(new StoredField(name, String.valueOf(value)));
                            allBldr.append(value).append(" ");
                            break;
                        default:
                            break;
                        }
                    }
                }
                doc.add(new StoredField(Key.MSGPHRASE.name(), multi.getMsgPhrase(def.getMsgPhrase())));
                doc.add(new TextField(Key.ALL.name(), allBldr.toString(), Store.NO));
                writer.updateDocument(new Term(Key.OID.name(), oid),
                        Index.getFacetsConfig().build(taxonomyWriter, doc));
                LOG.debug("Add Document: {}", doc);
            }
            writer.close();
            taxonomyWriter.close();
        } catch (final IOException | ClassNotFoundException | InstantiationException
                | IllegalAccessException e) {
            throw new EFapsException(Indexer.class, "IOException", e);
        } finally {
            Context.getThreadContext().setCompany(currentCompany);
            Context.getThreadContext().setLanguage(currentLanguage);
        }
    }
}

From source file:org.efaps.esjp.accounting.transaction.Calculation_Base.java

/**
 * Gets the JS 4 fit exchange rate./*from ww w .  j  a v a 2s  .  co m*/
 *
 * @param _parameter Parameter as passed by the eFaps API
 * @param _parameterClone the parameter clone
 * @return the JS 4 fit ex rate
 * @throws EFapsException on error
 */
protected StringBuilder getJS4Summarize(final Parameter _parameter, final Parameter _parameterClone)
        throws EFapsException {
    final StringBuilder ret = new StringBuilder();
    String postfix = null;
    boolean eval = true;
    while (eval) {
        eval = postfix == null;
        postfix = postfix == null ? "Debit" : "Credit";
        final String[] selected = _parameter.getParameterValues("posSelect_" + postfix);
        final String[] accountOids = _parameter.getParameterValues("accountLink_" + postfix);
        _parameter.getParameterValues("amount_" + postfix);

        // 1. find the selected account
        if (ArrayUtils.isNotEmpty(selected)) {
            String accountOid = null;
            for (int i = 0; i < selected.length; i++) {
                if (BooleanUtils.toBoolean(selected[i])) {
                    accountOid = accountOids[i];
                    break;
                }
            }
            final Collection<AccountInfo> accounts = new ArrayList<>();
            if (StringUtils.isNoneEmpty(accountOid)) {
                final TransInfo transInfo = new TransInfo();
                new Create().analysePositionsFromUI(_parameter, transInfo, postfix, null, false);

                AccountInfo sumAcc = null;
                for (final PositionInfo pos : transInfo.getPositions()) {
                    final Object[] rateObj = (Object[]) pos.getRate();
                    final RateInfo rateInfo = RateInfo.getDummyRateInfo();
                    rateInfo.setCurrencyInstance(pos.getRateCurrInst());
                    rateInfo.setTargetCurrencyInstance(pos.getCurrInst());
                    rateInfo.setRate((BigDecimal) rateObj[0]);
                    rateInfo.setRateUI((BigDecimal) rateObj[1]);
                    rateInfo.setSaleRate((BigDecimal) rateObj[0]);
                    rateInfo.setSaleRateUI((BigDecimal) rateObj[1]);

                    final AccountInfo info = new AccountInfo().setInstance(pos.getAccInst())
                            .setDescription("description").setRemark(pos.getRemark())
                            .addAmount(pos.getRateAmount().abs()).addAmountRate(pos.getAmount().abs())
                            .setCurrInstance(pos.getCurrInst()).setDocLink(pos.getDocInst())
                            .setLabelInst(pos.getLabelInst()).setRateInfo(rateInfo, "");

                    if (!pos.getAccInst().getOid().equals(accountOid)) {
                        accounts.add(info);
                    } else if (sumAcc == null) {
                        sumAcc = info;
                        accounts.add(info);
                    } else {
                        sumAcc.addAmount(pos.getRateAmount().abs()).addAmountRate(pos.getAmount().abs());
                    }
                }
                ret.append(new Evaluation().getTableJS(_parameterClone, postfix, accounts));
            }
        }
    }
    return ret;
}

From source file:org.flowable.cmmn.editor.json.converter.CmmnJsonConverter.java

public ObjectNode convertToJson(CmmnModel model, Map<String, CmmnModelInfo> formKeyMap,
        Map<String, CmmnModelInfo> decisionTableKeyMap) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;
    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }/* www.ja v a  2s  . c om*/

        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }
    maxX += 50;
    maxY += 50;

    if (maxX < 1485) {
        maxX = 1485;
    }

    if (maxY < 700) {
        maxY = 700;
    }

    modelNode.set("bounds", CmmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));

    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "CMMNDiagram");
    modelNode.set("stencil", stencilNode);

    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/cmmn1.1#");
    stencilsetNode.put("url", "../editor/stencilsets/cmmn1.1/cmmn1.1.json");
    modelNode.set("stencilset", stencilsetNode);

    ArrayNode shapesArrayNode = objectMapper.createArrayNode();

    Case caseModel = model.getPrimaryCase();

    ObjectNode propertiesNode = objectMapper.createObjectNode();
    if (StringUtils.isNotEmpty(caseModel.getId())) {
        propertiesNode.put(PROPERTY_CASE_ID, caseModel.getId());
    }
    if (StringUtils.isNotEmpty(caseModel.getName())) {
        propertiesNode.put(PROPERTY_NAME, caseModel.getName());
    }
    if (StringUtils.isNotEmpty(caseModel.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, caseModel.getDocumentation());
    }
    if (StringUtils.isNotEmpty(caseModel.getInitiatorVariableName())) {
        propertiesNode.put(PROPERTY_CASE_INITIATOR_VARIABLE_NAME, caseModel.getInitiatorVariableName());
    }

    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_CASE_NAMESPACE, model.getTargetNamespace());
    }

    modelNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);

    Stage planModelStage = caseModel.getPlanModel();
    GraphicInfo planModelGraphicInfo = model.getGraphicInfo(planModelStage.getId());
    ObjectNode planModelNode = CmmnJsonConverterUtil.createChildShape(planModelStage.getId(), STENCIL_PLANMODEL,
            planModelGraphicInfo.getX() + planModelGraphicInfo.getWidth(),
            planModelGraphicInfo.getY() + planModelGraphicInfo.getHeight(), planModelGraphicInfo.getX(),
            planModelGraphicInfo.getY());
    planModelNode.putArray(EDITOR_OUTGOING);
    shapesArrayNode.add(planModelNode);

    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    for (Criterion criterion : planModelStage.getExitCriteria()) {
        GraphicInfo criterionGraphicInfo = model.getGraphicInfo(criterion.getId());
        ObjectNode criterionNode = CmmnJsonConverterUtil.createChildShape(criterion.getId(),
                STENCIL_EXIT_CRITERION, criterionGraphicInfo.getX() + criterionGraphicInfo.getWidth(),
                criterionGraphicInfo.getY() + criterionGraphicInfo.getHeight(), criterionGraphicInfo.getX(),
                criterionGraphicInfo.getY());

        shapesArrayNode.add(criterionNode);
        ObjectNode criterionPropertiesNode = objectMapper.createObjectNode();
        criterionPropertiesNode.put(PROPERTY_OVERRIDE_ID, criterion.getId());
        new CriterionJsonConverter().convertElementToJson(criterionNode, criterionPropertiesNode, this,
                criterion, model);
        criterionNode.set(EDITOR_SHAPE_PROPERTIES, criterionPropertiesNode);

        if (CollectionUtils.isNotEmpty(criterion.getOutgoingAssociations())) {
            ArrayNode criterionOutgoingArrayNode = objectMapper.createArrayNode();
            for (Association association : criterion.getOutgoingAssociations()) {
                criterionOutgoingArrayNode.add(CmmnJsonConverterUtil.createResourceNode(association.getId()));
            }

            criterionNode.set("outgoing", criterionOutgoingArrayNode);
        }

        outgoingArrayNode.add(CmmnJsonConverterUtil.createResourceNode(criterion.getId()));
    }
    planModelNode.set("outgoing", outgoingArrayNode);

    ArrayNode planModelShapesArrayNode = objectMapper.createArrayNode();
    planModelNode.set(EDITOR_CHILD_SHAPES, planModelShapesArrayNode);

    processPlanItems(caseModel.getPlanModel(), model, planModelShapesArrayNode, formKeyMap, decisionTableKeyMap,
            planModelGraphicInfo.getX(), planModelGraphicInfo.getY());

    for (Association association : model.getAssociations()) {
        AssociationJsonConverter associationJsonConverter = new AssociationJsonConverter();
        associationJsonConverter.convertToJson(association, model, shapesArrayNode);
    }

    modelNode.set(EDITOR_CHILD_SHAPES, shapesArrayNode);
    return modelNode;
}

From source file:org.flowable.editor.language.json.converter.BpmnJsonConverter.java

public ObjectNode convertToJson(BpmnModel model, Map<String, ModelInfo> formKeyMap,
        Map<String, ModelInfo> decisionTableKeyMap) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;
    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }/*from   www  .  j ava  2s . com*/

        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }
    maxX += 50;
    maxY += 50;

    if (maxX < 1485) {
        maxX = 1485;
    }

    if (maxY < 700) {
        maxY = 700;
    }

    modelNode.set("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
    modelNode.put("resourceId", "canvas");

    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "BPMNDiagram");
    modelNode.set("stencil", stencilNode);

    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
    modelNode.set("stencilset", stencilsetNode);

    ArrayNode shapesArrayNode = objectMapper.createArrayNode();

    Process mainProcess = null;
    if (model.getPools().size() > 0) {
        mainProcess = model.getProcess(model.getPools().get(0).getId());
    } else {
        mainProcess = model.getMainProcess();
    }

    ObjectNode propertiesNode = objectMapper.createObjectNode();
    if (StringUtils.isNotEmpty(mainProcess.getId())) {
        propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
    }
    if (StringUtils.isNotEmpty(mainProcess.getName())) {
        propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
    }
    if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
    }
    if (mainProcess.isExecutable() == false) {
        propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
    }
    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
    }

    BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);

    BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
    BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
    BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
    BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);

    if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
        BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
    }

    modelNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);

    boolean poolHasDI = false;
    if (model.getPools().size() > 0) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo != null) {
                poolHasDI = true;
                break;
            }
        }
    }

    if (model.getPools().size() > 0 && poolHasDI) {
        for (Pool pool : model.getPools()) {
            GraphicInfo poolGraphicInfo = model.getGraphicInfo(pool.getId());
            if (poolGraphicInfo == null)
                continue;
            ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL,
                    poolGraphicInfo.getX() + poolGraphicInfo.getWidth(),
                    poolGraphicInfo.getY() + poolGraphicInfo.getHeight(), poolGraphicInfo.getX(),
                    poolGraphicInfo.getY());
            shapesArrayNode.add(poolNode);
            ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
            poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
            poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
            if (pool.isExecutable() == false) {
                poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
            }
            if (StringUtils.isNotEmpty(pool.getName())) {
                poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
            }
            poolNode.set(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);

            ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
            poolNode.set(EDITOR_CHILD_SHAPES, laneShapesArrayNode);

            ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
            poolNode.set("outgoing", outgoingArrayNode);

            Process process = model.getProcess(pool.getId());
            if (process != null) {
                Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
                for (Lane lane : process.getLanes()) {
                    GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
                    if (laneGraphicInfo == null)
                        continue;
                    ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE,
                            laneGraphicInfo.getX() + laneGraphicInfo.getWidth() - poolGraphicInfo.getX(),
                            laneGraphicInfo.getY() + laneGraphicInfo.getHeight() - poolGraphicInfo.getY(),
                            laneGraphicInfo.getX() - poolGraphicInfo.getX(),
                            laneGraphicInfo.getY() - poolGraphicInfo.getY());
                    laneShapesArrayNode.add(laneNode);
                    ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
                    lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
                    }
                    laneNode.set(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);

                    ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
                    laneNode.set(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
                    laneNode.set("outgoing", objectMapper.createArrayNode());

                    laneMap.put(lane.getId(), elementShapesArrayNode);
                }

                for (FlowElement flowElement : process.getFlowElements()) {

                    Lane laneForElement = null;
                    GraphicInfo laneGraphicInfo = null;

                    FlowElement lookForElement = null;
                    if (flowElement instanceof SequenceFlow) {
                        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                        lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());

                    } else {
                        lookForElement = flowElement;
                    }

                    for (Lane lane : process.getLanes()) {
                        if (lane.getFlowReferences().contains(lookForElement.getId())) {
                            laneGraphicInfo = model.getGraphicInfo(lane.getId());
                            if (laneGraphicInfo != null) {
                                laneForElement = lane;
                            }
                            break;
                        }
                    }

                    if (flowElement instanceof SequenceFlow || laneForElement != null) {
                        processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()),
                                formKeyMap, decisionTableKeyMap, laneGraphicInfo.getX(),
                                laneGraphicInfo.getY());
                    }
                }

                processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
            }

            for (MessageFlow messageFlow : model.getMessageFlows().values()) {
                if (messageFlow.getSourceRef().equals(pool.getId())) {
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
                }
            }
        }

        processMessageFlows(model, shapesArrayNode);

    } else {
        processFlowElements(model.getMainProcess(), model, shapesArrayNode, formKeyMap, decisionTableKeyMap,
                0.0, 0.0);
        processMessageFlows(model, shapesArrayNode);
    }

    modelNode.set(EDITOR_CHILD_SHAPES, shapesArrayNode);
    return modelNode;
}

From source file:org.jboss.aerogear.unifiedpush.auth.PathBasedKeycloakConfigResolver.java

@Override
public KeycloakDeployment resolve(Request request) {
    String realm = DEFAULT_REALM_FILE;

    AccessToken accessToken = BearerHelper.getTokenDataFromBearer(request).orNull();
    if (accessToken != null) {
        String issuer = accessToken.getIssuer();

        if (StringUtils.isNoneEmpty(issuer)) {
            issuer = URLUtils.removeLastSlash(issuer);
            String jwtRealm = URLUtils.getLastPart(issuer);

            if (!OAuth2Configuration.DEFAULT_OAUTH2_UPS_REALM.equalsIgnoreCase(jwtRealm)) {
                realm = "upsi";
            }/*www  .j  a v  a 2s  . c o m*/
        }
    }

    URI uri = URI.create(request.getURI());

    if (logger.isTraceEnabled())
        logger.trace("Identified Bearer request, using keycloak realm! URI: {}, realm: {}", uri.toString(),
                realm);

    String host = uri.getHost();
    CustomKeycloakDeployment deployment = cache.get(getCacheKey(realm, host));
    if (null == deployment) {
        InputStream is = null;

        try {
            is = applicationContext.getResource("/WEB-INF/" + realm + ".json").getInputStream();
        } catch (IOException e) {
            throw new IllegalStateException("Not able to find the file /" + realm + ".json");
        }

        if (is == null) {
            throw new IllegalStateException("Not able to find the file /" + realm + ".json");
        }

        deployment = CustomKeycloakDeploymentBuilder.build(is);

        String baseUrl = getBaseBuilder(deployment, request, deployment.getAuthServerBaseUrl()).build()
                .toString();
        KeycloakUriBuilder serverBuilder = KeycloakUriBuilder.fromUri(baseUrl);
        resolveUrls(deployment, serverBuilder);

        cache.put(getCacheKey(realm, host), deployment);
    }

    return deployment;
}

From source file:org.neo4art.importer.wikipedia.domain.WikipediaArtistPage.java

public WikipediaElement from(WikiArticle article) {
    String infobox = WikipediaElementTransformer.toWikipediaElement(this, article);

    if (StringUtils.isNoneEmpty(infobox)) {
        this.artist = WikipediaArtistInfoboxParser.parse(infobox);
    }/*from w  w w.j  av  a 2 s  . co m*/

    return this;
}

From source file:org.neo4art.importer.wikipedia.domain.WikipediaArtMovementPage.java

public WikipediaElement from(WikiArticle article) {
    String infobox = WikipediaElementTransformer.toWikipediaElement(this, article);

    if (StringUtils.isNoneEmpty(infobox)) {
        this.artMovement = WikipediaArtMovementInfoboxParser.parse(infobox);
    }//from   w w  w .j  a v a 2 s. c o m

    return this;
}