Example #1
0
 /**
  * Takes care of the id properties, either identifying the Ids or getting them from idProperties
  * of @Path
  *
  * @throws Exception
  */
 private void parseNodeProperty() throws Exception {
   if (Is.empty(treeAnnotation.idProperties())) {
     idProperties = "";
     for (Field field : nodeClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Id.class)) {
         if (!Is.empty(idProperties)) {
           idProperties = idProperties + ",";
         }
         idProperties = idProperties + field.getName();
       }
     }
   } else {
     idProperties = treeAnnotation.idProperties();
   }
   if (Is.empty(idProperties)) {
     throw new Exception(XavaResources.getString("error.nodePropertiesUndefined"));
   }
   String[] properties = idProperties.split(",");
   idPropertiesList = new ArrayList<String>();
   for (String property : properties) {
     if (!Is.empty(property.trim())) {
       idPropertiesList.add(property.trim());
     }
   }
 }
 private String getPDFLine(
     String number, String name, String hexValue, String useTo, String characteristicThing) {
   String s = "";
   s += Is.empty(number) ? "" : number + " ";
   s += Is.empty(name) ? "" : name + " ";
   s += Is.empty(hexValue) ? "" : hexValue + " ";
   s += Is.empty(useTo) ? "" : useTo + " ";
   s += Is.empty(characteristicThing) ? "" : characteristicThing + " ";
   return s.trim();
 }
 private void checkPreconditions() throws XavaException {
   if (Is.emptyString(getModel())) {
     throw new XavaException("descriptions_calculator_model_required", getClass().getName());
   }
   if (Is.emptyString(getKeyProperties())) {
     throw new XavaException("descriptions_calculator_keyProperty_required", getClass().getName());
   }
   if (Is.emptyString(getDescriptionProperties())) {
     throw new XavaException(
         "descriptions_calculator_descriptionProperty_required", getClass().getName());
   }
 }
Example #4
0
 public void setDefaultValues() {
   for (MetaTab t : MetaTabsDefaultValues.getMetaTabsForModel(getMetaComponent().getName())) {
     if (t.getMetaFilter() != null && getMetaFilter() == null) setMetaFilter(t.getMetaFilter());
     if (t.getMetaRowStyles() != null && getMetaRowStyles() == null)
       setMetaRowStyles(t.getMetaRowStyles());
     if (t.properties != null && properties == null) properties = t.properties;
     if (!Is.emptyString(t.getBaseCondition()) && Is.emptyString(getBaseCondition()))
       setBaseCondition(t.getBaseCondition());
     if (!Is.emptyString(t.getDefaultOrder()) & Is.emptyString(getDefaultOrder()))
       setDefaultOrder(t.getDefaultOrder());
   }
 }
Example #5
0
 public String getTable() {
   // Change this if by polymorphism ?
   if (isCodeGenerationTime()) return table;
   if (XavaPreferences.getInstance().isJPAPersistence()
       && getSchema() == null
       && !Is.emptyString(XPersistence.getDefaultSchema())) {
     return XPersistence.getDefaultSchema() + "." + table;
   } else if (XavaPreferences.getInstance().isHibernatePersistence()
       && getSchema() == null
       && !Is.emptyString(XHibernate.getDefaultSchema())) {
     return XHibernate.getDefaultSchema() + "." + table;
   }
   return table;
 }
Example #6
0
 /**
  * Returns the node name as it is used in the path
  *
  * @param object Object to be inspected.
  * @return The node name. It can be compound with multiple values (when you have multiple id, for
  *     example).
  */
 public String getNodeName(Object object) {
   String returnValue = "";
   Object value;
   for (String propertyName : idPropertiesList) {
     value = propertyName;
     try {
       value = PropertyUtils.getProperty(object, propertyName);
     } catch (IllegalAccessException e) {
       log.debug(e);
     } catch (InvocationTargetException e) {
       log.debug(e);
     } catch (NoSuchMethodException e) {
       log.debug(e);
     }
     if (!Is.empty(returnValue)) {
       returnValue = returnValue + getIdSeparator();
     }
     if (value != null) {
       returnValue = returnValue + value.toString();
     }
   }
   if (idPropertiesList.size() > 1) {
     returnValue = "<" + returnValue + ">";
   }
   return returnValue;
 }
Example #7
0
 public void execute() throws Exception {
   String userName = getView().getValueString("user");
   String password = getView().getValueString("password");
   if (Is.emptyString(userName, password)) {
     addError("unauthorized_user");
     return;
   }
   if (!SignInHelper.isAuthorized(userName, password)) {
     addError("unauthorized_user");
     return;
   }
   SignInHelper.signIn(getRequest().getSession(), userName);
   getView().reset();
   String originalURI = getRequest().getParameter("originalURI");
   if (originalURI == null) {
     forwardURI = "/";
   } else {
     int idx = originalURI.indexOf("/", 1);
     if (!originalURI.endsWith("/SignIn") && idx > 0 && idx < originalURI.length()) {
       forwardURI = originalURI.substring(idx);
     } else {
       forwardURI = "/";
     }
   }
 }
 public String getEJBQLCondition() throws XavaException {
   StringBuffer sb = new StringBuffer("SELECT OBJECT(o) FROM ");
   sb.append(getMetaModel().getName());
   sb.append(" o");
   if (!Is.emptyString(this.condition)) {
     sb.append(" WHERE ");
     String attributesCondition =
         getMetaModel().getMapping().changePropertiesByCMPAttributes(this.condition);
     sb.append(Strings.change(attributesCondition, getArgumentsJBoss11ToEJBQL()));
   }
   if (!Is.emptyString(this.order)) {
     sb.append(" ORDER BY ");
     sb.append(getMetaModel().getMapping().changePropertiesByCMPAttributes(this.order));
   }
   return sb.toString();
 }
Example #9
0
 /**
  * Parse the @TreeView annotation.
  *
  * @param nodeClass Object to be parsed.
  * @throws Exception
  */
 @SuppressWarnings("rawtypes")
 protected void parseTreeView(Tree path, Class nodeClass, Class parentClass, String collectionName)
     throws Exception {
   this.treeAnnotation = path;
   this.nodeClass = nodeClass;
   this.parentClass = parentClass;
   this.collectionName = collectionName;
   if (treeAnnotation == null) {
     treeAnnotation =
         this.getClass().getDeclaredField("defaultPathAnnotation").getAnnotation(Tree.class);
   }
   if (Is.empty(treeAnnotation.pathProperty())) {
     throw new XavaException("error.collectionDoesNotRepresentATreeView");
   }
   this.pathProperty = treeAnnotation.pathProperty();
   this.idSeparator = treeAnnotation.idSeparator();
   parseNodeProperty();
   this.orderProperty = null;
   this.initialExpandedState = treeAnnotation.initialExpandedState();
   this.keyIncrement = treeAnnotation.orderIncrement();
   if (this.keyIncrement < 2) {
     this.keyIncrement = 2;
   }
   setPathSeparator(treeAnnotation.pathSeparator());
   if (nodeClass.getClass().isAnnotationPresent(Id.class)) {
     entityObject = true;
   } else {
     entityObject = false;
   }
   parseOrderDefined();
   parseEntityObject();
 }
Example #10
0
 private List obtainPropertiesNamesUsedToCalculate() throws XavaException {
   Set result = new HashSet();
   Iterator itProperties = getMetaPropertiesCalculated().iterator();
   while (itProperties.hasNext()) {
     MetaProperty metaProperty = (MetaProperty) itProperties.next();
     if (!metaProperty.hasCalculator()) continue;
     MetaSetsContainer metaCalculator = metaProperty.getMetaCalculator();
     if (!metaCalculator.containsMetaSets()) continue;
     Iterator itSets = metaCalculator.getMetaSets().iterator();
     while (itSets.hasNext()) {
       MetaSet set = (MetaSet) itSets.next();
       String propertyNameFrom = set.getPropertyNameFrom();
       if (!Is.emptyString(propertyNameFrom)) {
         String qualifiedName = metaProperty.getQualifiedName();
         int idx = qualifiedName.indexOf('.');
         String ref = idx < 0 ? "" : qualifiedName.substring(0, idx + 1);
         String qualifiedPropertyNameFrom = ref + propertyNameFrom;
         if (!getPropertiesNames().contains(qualifiedPropertyNameFrom)) {
           result.add(qualifiedPropertyNameFrom);
         }
       }
     }
   }
   return new ArrayList(result);
 }
Example #11
0
  public String getQualifiedColumn(String modelProperty) throws XavaException {
    PropertyMapping propertyMapping = (PropertyMapping) propertyMappings.get(modelProperty);
    if (propertyMapping != null && propertyMapping.hasFormula()) return getColumn(modelProperty);

    String tableColumn = getTableColumn(modelProperty, true);
    if (Is.emptyString(tableColumn)) return "'" + modelProperty + "'";
    if (referencePropertyWithFormula) {
      referencePropertyWithFormula = false;
      return tableColumn;
    }
    // for calculated fields or created by multiple converter

    if (modelProperty.indexOf('.') >= 0) {
      if (tableColumn.indexOf('.') < 0) return tableColumn;
      String reference = modelProperty.substring(0, modelProperty.lastIndexOf('.'));
      if (tableColumn.startsWith(getTableToQualifyColumn() + ".")) {
        String member = modelProperty.substring(modelProperty.lastIndexOf('.') + 1);
        if (getMetaModel().getMetaReference(reference).getMetaModelReferenced().isKey(member))
          return tableColumn;
      }

      // The next code uses the alias of the table instead of its name. In order to
      // support multiple references to the same model
      if (reference.indexOf('.') >= 0) {
        if (getMetaModel().getMetaProperty(modelProperty).isKey()) {
          reference = reference.substring(0, reference.lastIndexOf('.'));
        }
        reference = reference.replaceAll("\\.", "_");
      }
      return "T_" + reference + tableColumn.substring(tableColumn.lastIndexOf('.'));
    } else {
      return getTableToQualifyColumn() + "." + tableColumn;
    }
  }
Example #12
0
 public void testObtainAggregateValues() throws Exception {
   String city = getValueInList(0, "address.city");
   assertTrue(
       "Value for city in first customer is required for run this test", !Is.emptyString(city));
   execute("Mode.detailAndFirst");
   assertValue("address.city", city);
   assertNoLabel("addres.city");
 }
 /**
  * Extract from the viewObject the name of the collection.
  *
  * <p>Useful for using Tab actions for collections. <br>
  */
 public void setViewObject(String viewObject) {
   if (Is.emptyString(this.collection)) {
     this.collection = viewObject.substring("xava_view_".length());
     while (this.collection.startsWith("section")) {
       this.collection = this.collection.substring(this.collection.indexOf('_') + 1);
     }
   }
 }
 private String getHQLCondition(boolean order) throws XavaException {
   StringBuffer sb = new StringBuffer("from ");
   sb.append(getMetaModel().getName());
   sb.append(" as o");
   if (!Is.emptyString(this.condition)) {
     sb.append(" where ");
     String condition = transformAggregateProperties(getCondition());
     condition = Strings.change(condition, getArgumentsToHQL());
     sb.append(Strings.change(condition, getTokensToChangeDollarsAndNL()));
   }
   if (order && !Is.emptyString(this.order)) {
     sb.append(" order by ");
     sb.append(
         Strings.change(
             transformAggregateProperties(this.order), getTokensToChangeDollarsAndNL()));
   }
   return sb.toString();
 }
 private Collection getKeyPropertiesCollection() {
   if (keyPropertiesCollection == null) {
     keyPropertiesCollection = new ArrayList();
     String source = Is.emptyString(keyProperty) ? keyProperties : keyProperty;
     StringTokenizer st = new StringTokenizer(source, ",;");
     while (st.hasMoreElements()) {
       keyPropertiesCollection.add(st.nextToken().trim());
     }
   }
   return keyPropertiesCollection;
 }
 public void testPostmodifiyCalculatorNotOnRead() throws Exception {
   assertListNotEmpty();
   execute("Mode.detailAndFirst");
   assertNoErrors();
   String description = getValue("description");
   assertTrue("Description must have value", !Is.emptyString(description));
   execute("Mode.list");
   assertNoErrors();
   execute("Mode.detailAndFirst");
   assertNoErrors();
   assertValue("description", description); // No changed on read
 }
 protected Tab getTab() throws XavaException {
   if (tab == null) {
     String tabObject =
         Is.emptyString(collection)
             ? "xava_tab"
             : Tab.COLLECTION_PREFIX + Strings.change(collection, ".", "_");
     tab = (Tab) getContext().get(getRequest(), tabObject);
     if (tab.getCollectionView() != null) {
       tab.getCollectionView().refreshCollections();
     }
   }
   return tab;
 }
Example #18
0
 public static String getTitleI18n(Locale locale, String modelName, String tabName)
     throws XavaException {
   String id = null;
   if (Is.emptyString(tabName)) {
     id = modelName + ".tab.title";
   } else {
     id = modelName + ".tabs." + tabName + ".title";
   }
   if (Labels.existsExact(id, locale)) {
     return Labels.get(id, locale);
   } else {
     return null;
   }
 }
  public static void setCurrent(HttpServletRequest request) {
    Object rundata = request.getAttribute("rundata");
    String portalUser = (String) request.getSession().getAttribute("xava.portal.user");
    String webUser = (String) request.getSession().getAttribute("xava.user");
    String user = portalUser == null ? webUser : portalUser;
    if (Is.emptyString(user) && rundata != null) {
      PropertiesManager pmRundata = new PropertiesManager(rundata);
      try {
        Object jetspeedUser = pmRundata.executeGet("user");
        PropertiesManager pmUser = new PropertiesManager(jetspeedUser);
        user = (String) pmUser.executeGet("userName");
      } catch (Exception ex) {
        log.warn(XavaResources.getString("warning_get_user"), ex);
        user = null;
      }
    }
    municipioUsuario.set(user);
    request.getSession().setAttribute("xava.user", user);

    municipioUsuarioInfo.set(request.getSession().getAttribute("xava.portal.userinfo"));
  }
Example #20
0
 /**
  * Creates the implementation of TreeView reader
  *
  * @return Object implementing the ITreeViewReader
  * @throws Exception
  */
 @SuppressWarnings({"unchecked", "rawtypes"})
 public ITreeViewReader getTreeViewReaderImpl() {
   if (treeViewReader == null && !Is.emptyString(treeViewReaderName)) {
     try {
       Class clazz = Class.forName(treeViewReaderName);
       if (clazz.isAssignableFrom(ITreeViewReader.class)) {
         treeViewReader = (ITreeViewReader) clazz.newInstance();
       }
     } catch (ClassNotFoundException e) {
       log.error(e);
     } catch (InstantiationException e) {
       log.error(e);
     } catch (IllegalAccessException e) {
       log.error(e);
     }
     if (treeViewReader == null) {
       treeViewReader = new TreeViewReaderImpl();
     }
   }
   return treeViewReader;
 }
Example #21
0
 public void testValidValuesInList() throws Exception {
   int quantity = getListRowCount();
   assertTrue("For this test is needed at least one created delivery", quantity > 0);
   Collection values = new ArrayList();
   values.add("Lokal");
   values.add("Nachional");
   values.add("Internachional");
   boolean thereIsOne = false;
   for (int i = 0; i < quantity; i++) {
     String value = getValueInList(i, "distance");
     if (Is.emptyString(value)) continue;
     if (values.contains(value)) {
       thereIsOne = true;
       continue;
     }
     fail("Only the next values are valid: " + values);
   }
   assertTrue(
       "For this test is need at least one delivery with value in 'distance' property",
       thereIsOne);
 }
Example #22
0
  /** Determines if the property orderProperty was defined for the object. */
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void parseOrderDefined() {
    orderDefined = false;
    OrderBy orderBy = null;
    if (Is.empty(orderProperty)) {
      try {
        Field collectionField = parentClass.getDeclaredField(collectionName);
        if (collectionField.isAnnotationPresent(OrderBy.class)) {
          orderBy = collectionField.getAnnotation(OrderBy.class);
        }
      } catch (SecurityException e) {
        log.error(e);
      } catch (NoSuchFieldException e) {
        log.debug(e.getMessage());
      }

      if (orderBy == null) {
        Method collectionMethod = null;
        try {
          collectionMethod =
              parentClass.getDeclaredMethod(
                  "get" + Strings.firstUpper(collectionName), new Class[] {});
        } catch (Exception e) {
          log.debug(e);
        }
        if (collectionMethod == null) {
          try {
            collectionMethod =
                parentClass.getDeclaredMethod(
                    "is" + Strings.firstUpper(collectionName), new Class[] {});
          } catch (Exception e) {
            log.debug(e);
          }
        }
        if (collectionMethod != null && collectionMethod.isAnnotationPresent(OrderBy.class)) {
          orderBy = collectionMethod.getAnnotation(OrderBy.class);
        }
      }
      if (orderBy != null) {
        String[] fieldNames = orderBy.value().split(",");
        if (fieldNames.length > 0) {
          orderProperty = fieldNames[fieldNames.length - 1].trim();
        }
      }
    }
    if (!Is.empty(orderProperty)) {
      try {
        Object itemObject = nodeClass.newInstance();
        Class propertyType = PropertyUtils.getPropertyType(itemObject, orderProperty);
        if (propertyType.isAssignableFrom(Integer.class)) {
          orderDefined = true;
        }
      } catch (IllegalAccessException e) {
        log.error(e);
      } catch (InvocationTargetException e) {
        log.error(e);
      } catch (NoSuchMethodException e) {
        log.error(e);
      } catch (Exception e) {
        log.error(e);
      }
    }
  }
 public void validate(Messages errors) throws Exception {
   if (Is.emptyString(getDescription())) {
     errors.add("blank_description");
   }
 }
  public void execute() throws Exception {
    // TODO Auto-generated method stub

    Long key = (Long) getView().getAllValues().get("id");

    System.out.println("\n\n\n\n\n\n\n\n\n\n The value sent===" + getView().getAllValues());
    Map payingAcct = (Map) getView().getAllValues().get("payingAccount");

    PaymentBatch batch = XPersistence.getManager().find(PaymentBatch.class, key);
    TransitAccount debitAccount = batch.getPayingAccount();

    if (payingAcct.get("id") != null) {
      debitAccount = (TransitAccount) MapFacade.findEntity("TransitAccount", payingAcct);
      batch.setPayingAccount(debitAccount);
      XPersistence.getManager().merge(batch);
    }
    if (UserManager.loginUserHasRole("funder") && debitAccount == null) {
      addError("As funder, You Need to Attach Debit Account", null);
      return;
    }

    Long transId = (Long) getView().getObject("transId");

    Boolean fina = (Boolean) getView().getObject("final");

    if (fina) {
      if (debitAccount == null) {
        addError(" Debit Account Yet To be Attached", null);
        return;
      }
      String token = (String) getView().getObject("token");
      String softToken = (String) getView().getValue("softToken");
      if (Is.empty(softToken)) {
        addError("Soft Token Is Required", null);
        return;
      }
      DateTime dT = (DateTime) getView().getObject("fiveMinutes");
      DateTime presentTime = new DateTime(Dates.withTime(Dates.createCurrent()));

      if (!Is.equalAsStringIgnoreCase(token, softToken)) {
        addError("Incorrect Soft Token", null);
        return;
      }
      if (dT.getMillis() < presentTime.getMillis()) {
        addError("Token Has Expired", null);
        return;
      }

      System.out.println(
          "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The sent object to this place ===" + transId);
    }

    Transaction transaction = XPersistence.getManager().find(Transaction.class, transId);

    AsyncEventBus eventBus = new AsyncEventBus(Executors.newCachedThreadPool());
    eventBus.register(transaction);
    System.out.println(" 1111111approve already commented out......... ");
    eventBus.post(new Object());

    // transaction.approve();
    closeDialog();
    setNextMode(LIST);
  }
 private boolean isMultipleKey() {
   return !Is.emptyString(keyProperties);
 }
 private boolean hasCondition() {
   return !Is.emptyString(condition);
 }
 private boolean hasOrder() {
   return !Is.emptyString(order);
 }
 public String getDescriptionProperties() {
   return Is.emptyString(descriptionProperties) ? getDescriptionProperty() : descriptionProperties;
 }
 private boolean isAggregate() {
   return !Is.emptyString(aggregateName);
 }
 /**
  * It's used when there are more than one property that it's key, or with only one It's preferred
  * use a wrapper class as primary key.
  *
  * <p>It's exclusive with <tt>keyProperties</tt>.
  */
 public String getKeyProperties() {
   return Is.emptyString(keyProperties) ? getKeyProperty() : keyProperties;
 }