/** * @param parameter * @return * @throws DynamicExtensionsApplicationException * @throws DynamicExtensionsSystemException */ private List<NameValueBean> getAttributesForForm(String formId) throws DynamicExtensionsSystemException, DynamicExtensionsApplicationException { ArrayList<NameValueBean> formAttributesList = new ArrayList<NameValueBean>(); if (formId != null) { Logger.out.debug("Fetching attributes for [" + formId + "]"); ContainerInterface container = DynamicExtensionsUtility.getContainerByIdentifier(formId); if (container != null) { // Collection<ControlInterface> controlCollection = container.getControlCollection(); Collection<ControlInterface> controlCollection = container.getAllControls(); if (controlCollection != null) { NameValueBean controlName = null; AbstractAttributeInterface abstractAttribute = null; AttributeInterface attribute = null; for (ControlInterface control : controlCollection) { if (control != null) { // if control contains Attribute interface object then only show on UI. // If control contains association objects do not show in attribute list abstractAttribute = control.getAbstractAttribute(); if (abstractAttribute != null && (abstractAttribute instanceof AttributeInterface)) { attribute = (AttributeInterface) abstractAttribute; if (!(attribute.getAttributeTypeInformation() instanceof FileAttributeTypeInformation)) { controlName = new NameValueBean(control.getCaption(), control.getId()); formAttributesList.add(controlName); } } } } } } } return formAttributesList; }
/** * Returns <code>EntityInterface</code> object for given entity name and attributes. * * @param entityName * @param attributes * @return EntityInterface */ private EntityInterface createEntity(String entityName, String... attributes) { EntityInterface entity = DomainObjectFactory.getInstance().createEntity(); entity.setName(entityName); for (String name : attributes) { AttributeInterface attr = DomainObjectFactory.getInstance().createStringAttribute(); attr.setName(name); attr.setId(recordId++); entity.addAttribute(attr); allowedAttributes.add(attr); } return entity; }
/** * To add the Id columns of MainEntities in the SQL if its not present. It will also populate * entityIdIndexMap passes it. * * @param columnIndex columnIndex * @param selectSql selectSql * @param entityIdIndexMap entityIdIndexMap * @param selectSqlColumnList selectSqlColumnList * @param outputTreeDataNode outputTreeDataNode * @return The modified SQL string. */ private static Map putIdColumnsInSql( int colIndex, String selectSql, Map<EntityInterface, Integer> entityIdIndexMap, List<String> selectSqlColumnList, OutputTreeDataNode outputTreeDataNode, Map<String, String> specimenMap, Map<String, String> columnNameVsAliasMap) { int columnIndex = colIndex; StringBuffer sql = new StringBuffer(selectSql); Map sqlIndexMap = new HashMap(); if (outputTreeDataNode != null) { List<QueryOutputTreeAttributeMetadata> attributes = outputTreeDataNode.getAttributes(); for (QueryOutputTreeAttributeMetadata attributeMetaData : attributes) { AttributeInterface attribute = attributeMetaData.getAttribute(); String sqlColumnName = attributeMetaData.getColumnName().trim(); if (attribute.getName().equals(AQConstants.IDENTIFIER)) { int index = selectSqlColumnList.indexOf( columnNameVsAliasMap.get(sqlColumnName) + " " + sqlColumnName); if (index >= 0) { entityIdIndexMap.put(attribute.getEntity(), index); break; } else { // appendColNameToSql(selectSql, sql, sqlColumnName); entityIdIndexMap.put(attribute.getEntity(), null); columnIndex++; if (outputTreeDataNode .getOutputEntity() .getDynamicExtensionsEntity() .getName() .equals("edu.wustl.catissuecore.domain.Specimen")) { if (specimenMap == null) { specimenMap = new HashMap<String, String>(); } specimenMap.put("specimenKey", "edu.wustl.catissuecore.domain.Specimen"); specimenMap.put("columnIndex", String.valueOf(columnIndex - 1)); } break; } } } } sqlIndexMap.put(AQConstants.SQL, sql.toString()); sqlIndexMap.put(AQConstants.ID_COLUMN_ID, columnIndex); return sqlIndexMap; }
/** * @param strToCreateObject strToCreateObject * @param oprVsLstOfVals Map * @param expression expression */ private static void processRules( StringBuffer strToCreateObject, Map<RelationalOperator, List<String>> oprVsLstOfVals, IExpression expression) { ICondition idCondition = null; Rule rule = ((Rule) (expression.getOperand(0))); for (ICondition condition : rule) { AttributeInterface conditionAttr = condition.getAttribute(); String attrName = conditionAttr.getName(); if (attrName.equalsIgnoreCase("id")) { idCondition = processRuleForId(oprVsLstOfVals, condition); } else { processRuleForOtherAttributes(strToCreateObject, condition, conditionAttr, attrName); } } // rule.removeCondition(idCondition); }
/** * Mock method for creating category records. * * @param catClass * @param howMany * @return */ private List<ICategorialClassRecord> createRecord(CategorialClass catClass, int howMany) { List<ICategorialClassRecord> records = new ArrayList<ICategorialClassRecord>(howMany); Collection<AttributeInterface> collection = catClass.getCategorialClassEntity().getAttributeCollection(); Set<AttributeInterface> set = new HashSet<AttributeInterface>(collection); for (int i = 0; i < howMany; i++) { ICategorialClassRecord record = QueryResultFactory.createCategorialClassRecord( catClass, set, new RecordId(recordId++ + "", "")); for (AttributeInterface attr : record.getAttributes()) { record.putStringValueForAttribute(attr, attr.getName() + "_R_" + counter); } records.add(record); counter++; } return records; }
/** * @see * edu.common.dynamicextensions.validation.ValidatorRuleInterface#validate(edu.common.dynamicextensions.domaininterface.AttributeInterface, * java.lang.Object, java.util.Map) * @throws DynamicExtensionsValidationException */ public boolean validate( AttributeInterface attribute, Object valueObject, Map<String, String> parameterMap) throws DynamicExtensionsValidationException { boolean valid = false; String attributeName = attribute.getName(); AttributeTypeInformationInterface attributeTypeInformation = attribute.getAttributeTypeInformation(); if (((valueObject != null) && (!((String) valueObject).trim().equals(""))) && ((attributeTypeInformation != null) && (attributeTypeInformation instanceof DateAttributeTypeInformation))) { DateAttributeTypeInformation dateAttributeTypeInformation = (DateAttributeTypeInformation) attributeTypeInformation; String dateFormat = dateAttributeTypeInformation.getFormat(); String value = (String) valueObject; if (dateFormat.equals(ProcessorConstants.MONTH_YEAR_FORMAT)) { value = DynamicExtensionsUtility.formatMonthAndYearDate(value); value = value.substring(0, value.length() - 4); } if (dateFormat.equals(ProcessorConstants.YEAR_ONLY_FORMAT)) { value = DynamicExtensionsUtility.formatYearDate(value); value = value.substring(0, value.length() - 4); } try { Date date = null; date = Utility.parseDate(value, "MM-dd-yyyy"); if (date != null) { valid = true; } } catch (ParseException parseException) { List<String> placeHolders = new ArrayList<String>(); placeHolders.add(attributeName); placeHolders.add(dateFormat); throw new DynamicExtensionsValidationException( "Validation failed", null, "dynExtn.validation.Date", placeHolders); } } return valid; }
/** * Writes output into csv file. * * @param masterList * @param num * @throws Exception */ private void write(List<Map<AttributeInterface, Object>> masterList, int num) throws Exception { BufferedWriter bos = new BufferedWriter(new FileWriter(new File("c:/test" + num + ".csv"))); for (AttributeInterface a : allowedAttributes) { bos.write(a.getName()); bos.write(","); } bos.write("\n"); for (Map<AttributeInterface, Object> map : masterList) { for (AttributeInterface a : allowedAttributes) { System.out.println(a.getName()); Object obj = map.get(a); String str = "-"; if (obj != null) { str = obj.toString(); } bos.write(str); bos.write(","); } bos.write("\n"); } bos.flush(); }
/** * Modify rule for attributes other than id. * * @param strToCreateObject strToCreateObject * @param condition condition * @param conditionAttr conditionAttr * @param attrName attrName */ private static void processRuleForOtherAttributes( StringBuffer strToCreateObject, ICondition condition, AttributeInterface conditionAttr, String attrName) { Long attrId = conditionAttr.getId(); RelationalOperator operator = condition.getRelationalOperator(); strToCreateObject .append("@#condition#@") .append(attrName) .append(attrId) .append(AQConstants.CONDITION_SEPERATOR) .append(operator.getStringRepresentation()); if (operator.equals(RelationalOperator.In) || operator.equals(RelationalOperator.NotIn)) { modifyQueryStringForInNotIn(strToCreateObject, condition.getValues()); } else if (!(operator.equals(RelationalOperator.IsNotNull) || operator.equals(RelationalOperator.IsNull))) { strToCreateObject.append(AQConstants.CONDITION_SEPERATOR).append(condition.getValue()); } strToCreateObject.append(';'); }
/** * @param request * @param gridControlsIds * @return */ private String updateControlsSequence(HttpServletRequest request, String controlsSeqNumbers) { System.out.println("ControlsId " + controlsSeqNumbers); ContainerInterface containerInterface = WebUIManager.getCurrentContainer(request); if (containerInterface != null) { Collection<ControlInterface> oldControlsCollection = containerInterface.getControlCollection(); if (oldControlsCollection != null) { Integer[] sequenceNumbers = DynamicExtensionsUtility.convertToIntegerArray( controlsSeqNumbers, ProcessorConstants.CONTROLS_SEQUENCE_NUMBER_SEPARATOR); ControlInterface[] oldControlsArray = oldControlsCollection.toArray(new ControlInterface[oldControlsCollection.size()]); // adding id attribute to attributecollection AttributeInterface idAttribute = null; Collection<AttributeInterface> attributeCollection = containerInterface.getEntity().getAttributeCollection(); for (AttributeInterface attributeIterator : attributeCollection) { // Added null check for bug 6013 if (attributeIterator.getColumnProperties() != null && attributeIterator.getColumnProperties().getName() != null && attributeIterator .getColumnProperties() .getName() .equals(DynamicExtensionsQueryBuilderConstantsInterface.IDENTIFIER)) { idAttribute = attributeIterator; break; } } // remove old controls from collection containerInterface.removeAllControls(); containerInterface.getEntity().removeAllAbstractAttributes(); ControlInterface control = null; if (sequenceNumbers != null) { for (int i = 0; i < sequenceNumbers.length; i++) { control = DynamicExtensionsUtility.getControlBySequenceNumber( oldControlsArray, sequenceNumbers[i].intValue()); System.out.println(control); if (control != null) { containerInterface.addControl(control); containerInterface.getEntity().addAbstractAttribute(control.getAbstractAttribute()); } } } if (idAttribute != null) { containerInterface.getEntity().addAbstractAttribute(idAttribute); } // Added by Rajesh for removing deleted associations and it's path from path tables. List<Long> deletedIdList = (List<Long>) CacheManager.getObjectFromCache( request, WebUIManagerConstants.DELETED_ASSOCIATION_IDS); List<Long> listOfIds = DynamicExtensionsUtility.getDeletedAssociationIds(oldControlsArray, sequenceNumbers); if (deletedIdList == null) { deletedIdList = listOfIds; } else { deletedIdList.addAll(listOfIds); } CacheManager.addObjectToCache( request, WebUIManagerConstants.DELETED_ASSOCIATION_IDS, deletedIdList); // System.out.println("deletedIdList : " + deletedIdList.size()); } } System.out.println("Coontrols Colln : "); Collection<ControlInterface> controlCollection = containerInterface.getControlCollection(); for (ControlInterface control : controlCollection) { System.out.println("[" + control.getSequenceNumber() + "] = [" + control.getCaption() + "]"); } return ""; }