@Override
  public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);

    element.setAttribute(
        "ceylon-module", (String) ObjectUtils.defaultIfNull(getCeylonModule(), ""));
    element.setAttribute(
        "top-level", (String) ObjectUtils.defaultIfNull(getTopLevelNameFull(), ""));
  }
Exemplo n.º 2
0
  /** @see org.displaytag.util.RequestHelper#getParameterMap() */
  public Map getParameterMap() {

    Map map = new HashMap();

    // get the parameters names
    Enumeration parametersName = this.request.getParameterNames();

    while (parametersName.hasMoreElements()) {
      // ... get the value
      String paramName = (String) parametersName.nextElement();

      request.getParameter(paramName);
      // put key/value in the map
      String[] originalValues =
          (String[])
              ObjectUtils.defaultIfNull(this.request.getParameterValues(paramName), new String[0]);
      String[] values = new String[originalValues.length];

      for (int i = 0; i < values.length; i++) {
        try {
          values[i] =
              URLEncoder.encode(
                  StringUtils.defaultString(originalValues[i]),
                  StringUtils.defaultString(
                      response.getCharacterEncoding(), "UTF8")); // $NON-NLS-1$
        } catch (UnsupportedEncodingException e) {
          throw new UnhandledException(e);
        }
      }
      map.put(paramName, values);
    }

    // return the Map
    return map;
  }
  /**
   * Loads the Notes for the note target on this Document.
   *
   * @param document the document for which to load the notes
   */
  protected void loadNotes(final Document document) {
    if (isNoteTargetReady(document)) {
      Object legacyObjectClass;
      if (document instanceof MaintenanceDocument) {
        MaintenanceDocument mdoc = (MaintenanceDocument) document;
        legacyObjectClass =
            ((Maintainable)
                    org.apache.commons.lang.ObjectUtils.defaultIfNull(
                        mdoc.getOldMaintainableObject(), mdoc.getNewMaintainableObject()))
                .getDataObjectClass();
      } else {
        legacyObjectClass = document.getClass();
      }

      List<Note> notes = new ArrayList<Note>();
      if (StringUtils.isNotBlank(document.getNoteTarget().getObjectId())) {
        notes.addAll(getNoteService().getByRemoteObjectId(document.getNoteTarget().getObjectId()));
      }
      // notes created on 'disapprove' are linked to Doc Header, so this checks that even if
      // notetype = BO
      if (document.getNoteType().equals(NoteType.BUSINESS_OBJECT)
          && document.getDocumentHeader().getWorkflowDocument().isDisapproved()) {
        notes.addAll(
            getNoteService().getByRemoteObjectId(document.getDocumentHeader().getObjectId()));
      }

      document.setNotes(notes);
    }
  }
  @Override
  protected ActionForward executeAction(final ActionContext context) throws Exception {
    final HttpServletRequest request = context.getRequest();
    final TransferType transferType = resolveTransferType(context);
    if (transferType == null) {
      // TT not found
      return null;
    }

    final Collection<PaymentCustomField> customFields =
        paymentCustomFieldService.list(transferType, false);
    if (CollectionUtils.isEmpty(customFields)) {
      // No custom fields
      return null;
    }

    // Set some specific use cases attributes
    final boolean isForLoan = CoercionHelper.coerce(boolean.class, request.getParameter("forLoan"));
    final String fieldName = isForLoan ? "loan(customValues).field" : "customValues.field";
    final String valueName = isForLoan ? "loan(customValues).value" : "customValues.value";
    request.setAttribute("isForLoan", isForLoan);
    request.setAttribute("fieldName", fieldName);
    request.setAttribute("valueName", valueName);
    request.setAttribute(
        "columnWidth",
        ObjectUtils.defaultIfNull(
            StringHelper.removeMarkupTags(request.getParameter("columnWidth")), "25%"));

    // Delegate the rendering to a jsp
    request.setAttribute("customFields", customFields);
    context.getResponse().setContentType("text/html");
    return new ActionForward("/pages/payments/paymentCustomFields.jsp", false);
  }
 public String getRegistryURL() {
   Connection connection = getConnection();
   if (connection != null) {
     Map<String, Object> properties = connection.getExtendedProperties();
     return (String)
         ObjectUtils.defaultIfNull(properties.get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY), "");
   }
   return "";
 }
Exemplo n.º 6
0
  /**
   *
   *
   * <pre>
   * call hql unique result (returns one or null)
   *
   * e.g.
   *
   * Hib3GroupDAO hib3GroupDAO = HibernateSession.byHqlStatic()
   * .createQuery("from Hib3GroupDAO as g where g.uuid = :uuid")
   *  .setCacheable(false)
   *  .setCacheRegion(KLASS + ".Exists")
   *  .setString("uuid", uuid).uniqueResult(Hib3GroupDAO.class);
   *
   * </pre>
   *
   * @param returnType type of the result (in future can use this for typecasting)
   * @param theCriterions are the criterions to use (pack multiple with HibUtils.listCrit())
   * @param <T> is the template
   * @return the object or null if none found
   * @throws GrouperDAOException
   */
  public <T> T uniqueResult(Class<T> returnType, Criterion theCriterions)
      throws GrouperDAOException {
    this.persistentClass = returnType;
    this.criterions = theCriterions;
    try {
      GrouperTransactionType grouperTransactionTypeToUse =
          (GrouperTransactionType)
              ObjectUtils.defaultIfNull(
                  this.grouperTransactionType, GrouperTransactionType.READONLY_OR_USE_EXISTING);

      T result =
          (T)
              HibernateSession.callbackHibernateSession(
                  grouperTransactionTypeToUse,
                  AuditControl.WILL_NOT_AUDIT,
                  new HibernateHandler() {

                    public Object callback(HibernateHandlerBean hibernateHandlerBean)
                        throws GrouperDAOException {
                      HibernateSession hibernateSession =
                          hibernateHandlerBean.getHibernateSession();

                      Session session = hibernateSession.getSession();
                      Criteria criteria = ByCriteriaStatic.this.attachCriteriaInfo(session);
                      GrouperContext.incrementQueryCount();
                      Object object = criteria.uniqueResult();
                      HibUtils.evict(hibernateSession, object, true);
                      return object;
                    }
                  });

      return result;
    } catch (GrouperStaleObjectStateException e) {
      throw e;
    } catch (RuntimeException e) {

      String errorString = "Exception in uniqueResult: (" + returnType + "), " + this;

      if (!GrouperUtil.injectInException(e, errorString)) {
        LOG.error(errorString, e);
      }

      throw e;
    }
  }
Exemplo n.º 7
0
  private Bucket doIndex(Resource resource, @Nullable Resource parentReference) {
    Bucket bucket = getBucket(resource);
    if (bucket != null) {
      return bucket;
    }

    if (StringUtils.isBlank(resource.getKey())) {
      LOG.warn("Unable to index a resource without key " + resource);
      return null;
    }

    Resource parent = null;
    if (!ResourceUtils.isLibrary(resource)) {
      // a library has no parent
      parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
    }

    Bucket parentBucket = getBucket(parent);
    if (parentBucket == null && parent != null) {
      LOG.warn("Resource ignored, parent is not indexed: " + resource);
      return null;
    }

    if (ResourceUtils.isProject(resource)
        || /* For technical projects */ ResourceUtils.isRootProject(resource)) {
      resource.setEffectiveKey(resource.getKey());
    } else {
      resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
    }
    bucket = new Bucket(resource).setParent(parentBucket);
    addBucket(resource, bucket);

    Resource parentResource = parentBucket != null ? parentBucket.getResource() : null;
    resourceCache.add(resource, parentResource);

    return bucket;
  }
Exemplo n.º 8
0
  private Bucket doIndex(Resource resource, Resource parentReference) {
    Bucket bucket = buckets.get(resource);
    if (bucket != null) {
      return bucket;
    }

    checkLock(resource);

    Resource parent = null;
    if (!ResourceUtils.isLibrary(resource)) {
      // a library has no parent
      parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
    }

    Bucket parentBucket = getBucket(parent, true);
    if (parentBucket == null && parent != null) {
      LOG.warn("Resource ignored, parent is not indexed: " + resource);
      return null;
    }

    resource.setEffectiveKey(createUID(currentProject, resource));
    bucket = new Bucket(resource).setParent(parentBucket);
    buckets.put(resource, bucket);

    boolean excluded = checkExclusion(resource, parentBucket);
    if (!excluded) {
      Snapshot snapshot =
          persistence.saveResource(
              currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null));
      if (ResourceUtils.isPersistable(resource)
          && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
        graph.addComponent(resource, snapshot);
      }
    }

    return bucket;
  }
Exemplo n.º 9
0
 public NewRule setStatus(@Nullable RuleStatus s) {
   this.status = (RuleStatus) ObjectUtils.defaultIfNull(s, RuleStatus.defaultStatus());
   return this;
 }
Exemplo n.º 10
0
 /** always returns true or false */
 public boolean booleanPrimitiveValueOfParameterNamed(final String parameterName) {
   final Boolean value =
       this.fromApiJsonHelper.extractBooleanNamed(parameterName, this.parsedCommand);
   return (Boolean) ObjectUtils.defaultIfNull(value, Boolean.FALSE);
 }
Exemplo n.º 11
0
  /**
   *
   *
   * <pre>
   * call hql unique result (returns one or null)
   *
   * e.g.
   *
   * List<Hib3GroupTypeTupleDAO> hib3GroupTypeTupleDAOs =
   *  HibernateSession.byHqlStatic()
   *    .createQuery("from Hib3GroupTypeTupleDAO as gtt where gtt.groupUuid = :group")
   *    .setCacheable(false).setString("group", uuid).list(Hib3GroupTypeTupleDAO.class);
   * </pre>
   *
   * @param returnType type of the result (can typecast)
   * @param theCriterions are the criterions to use (pack multiple with HibUtils.listCrit())
   * @param <T> is the template
   * @return the list or the empty list if not found (never null)
   * @throws GrouperDAOException
   */
  public <T> List<T> list(Class<T> returnType, Criterion theCriterions) throws GrouperDAOException {
    this.persistentClass = returnType;
    this.criterions = theCriterions;
    try {
      GrouperTransactionType grouperTransactionTypeToUse =
          (GrouperTransactionType)
              ObjectUtils.defaultIfNull(
                  this.grouperTransactionType, GrouperTransactionType.READONLY_OR_USE_EXISTING);

      List<T> result =
          (List<T>)
              HibernateSession.callbackHibernateSession(
                  grouperTransactionTypeToUse,
                  AuditControl.WILL_NOT_AUDIT,
                  new HibernateHandler() {

                    public Object callback(HibernateHandlerBean hibernateHandlerBean)
                        throws GrouperDAOException {
                      HibernateSession hibernateSession =
                          hibernateHandlerBean.getHibernateSession();

                      Session session = hibernateSession.getSession();
                      List<T> list = null;

                      // see if we are even retrieving the results
                      if (ByCriteriaStatic.this.queryOptions == null
                          || ByCriteriaStatic.this.queryOptions.isRetrieveResults()) {
                        Criteria criteria = ByCriteriaStatic.this.attachCriteriaInfo(session);
                        GrouperContext.incrementQueryCount();
                        // not sure this can ever be null, but make sure not to make iterating
                        // results easier
                        list = GrouperUtil.nonNull(criteria.list());
                        HibUtils.evict(hibernateSession, list, true);
                      }
                      // no nulls
                      list = GrouperUtil.nonNull(list);
                      QueryPaging queryPaging =
                          ByCriteriaStatic.this.queryOptions == null
                              ? null
                              : ByCriteriaStatic.this.queryOptions.getQueryPaging();

                      // now see if we should get the query count
                      boolean retrieveQueryCountNotForPaging =
                          ByCriteriaStatic.this.queryOptions != null
                              && ByCriteriaStatic.this.queryOptions.isRetrieveCount();
                      boolean findQueryCount =
                          (queryPaging != null && queryPaging.isDoTotalCount())
                              || (retrieveQueryCountNotForPaging);
                      if (findQueryCount) {

                        long resultSize = -1;
                        if (queryPaging != null) {
                          // see if we already know the total size (if less than page size and first
                          // page)
                          resultSize = GrouperUtil.length(list);
                          if (resultSize >= queryPaging.getPageSize()) {
                            resultSize = -1;
                          } else {
                            // we are on the last page, see how many records came before us, add
                            // those in
                            resultSize +=
                                (queryPaging.getPageSize() * (queryPaging.getPageNumber() - 1));
                          }
                        }

                        // do this if we dont have a total, or if we are not caching the total
                        if ((queryPaging != null
                                && (queryPaging.getTotalRecordCount() < 0
                                    || !queryPaging.isCacheTotalCount()))
                            || resultSize > -1
                            || retrieveQueryCountNotForPaging) {

                          // if we dont already know the size
                          if (resultSize == -1) {
                            queryCountQueries++;

                            Criteria countQuery =
                                StringUtils.isBlank(ByCriteriaStatic.this.alias)
                                    ? session.createCriteria(ByCriteriaStatic.this.persistentClass)
                                    : session.createCriteria(ByCriteriaStatic.this.alias);

                            // turn it into a row count
                            countQuery.setProjection(
                                Projections.projectionList().add(Projections.rowCount()));

                            // add criterions
                            if (ByCriteriaStatic.this.criterions != null) {
                              countQuery.add(ByCriteriaStatic.this.criterions);
                            }
                            resultSize = (Long) countQuery.list().get(0);
                          }

                          if (queryPaging != null) {
                            queryPaging.setTotalRecordCount((int) resultSize);

                            // calculate the page stuff like how many pages etc
                            queryPaging.calculateIndexes();
                          }
                          if (retrieveQueryCountNotForPaging) {
                            ByCriteriaStatic.this.queryOptions.setCount(resultSize);
                          }
                        }
                      }

                      return list;
                    }
                  });

      return result;
    } catch (GrouperStaleObjectStateException e) {
      throw e;
    } catch (GrouperDAOException e) {
      GrouperUtil.injectInException(e, "Exception in list: (" + returnType + "), " + this);
      throw e;
    } catch (RuntimeException e) {
      GrouperUtil.injectInException(e, "Exception in list: (" + returnType + "), " + this);
      throw e;
    }
  }
Exemplo n.º 12
0
 /**
  * Transforms a comma-separated list String property in to a array of trimmed strings.
  *
  * <p>This works even if they are separated by whitespace characters (space char, EOL, ...)
  */
 static String[] getListFromProperty(Map<String, String> properties, String key) {
   return (String[])
       ObjectUtils.defaultIfNull(
           StringUtils.stripAll(StringUtils.split(properties.get(key), ',')), new String[0]);
 }
Exemplo n.º 13
0
 public static Object getApplicationMapValue(String key, Object defaultValue) {
   return ObjectUtils.defaultIfNull(
       FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(key),
       defaultValue);
 }