/** * @return a List of the names of fields which are marked in data dictionary as return fields. */ public List<String> getReturnKeys() { List<String> returnKeys; if (fieldConversions != null && !fieldConversions.isEmpty()) { returnKeys = new ArrayList<String>(fieldConversions.keySet()); } else { returnKeys = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(getBusinessObjectClass()); } return returnKeys; }
/** * Gets keys for the maintainable business object from the persistence metadata explorer. Checks for existence of key property * names as request parameters, if found adds them to the returned hash map. */ protected Map buildKeyMapFromRequest(Maintainable maintainable, HttpServletRequest request) { List keyFieldNames = null; // are override keys listed in the request? If so, then those need to be our keys, // not the primary keye fields for the BO if (!StringUtils.isBlank(request.getParameter(KRADConstants.OVERRIDE_KEYS))) { String[] overrideKeys = request.getParameter(KRADConstants.OVERRIDE_KEYS).split(KRADConstants.FIELD_CONVERSIONS_SEPARATOR); keyFieldNames = new ArrayList(); for (String overrideKey : overrideKeys) { keyFieldNames.add(overrideKey); } } else { keyFieldNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(maintainable.getBusinessObject().getClass()); } return getRequestParameters(keyFieldNames, maintainable, request); }
/** * This method creates a human-readable string of the class' primary key field names, as designated by the * DataDictionary. * * @param boClass * @return */ protected String getHumanReadablePrimaryKeyFieldNames(Class<?> boClass) { String delim = ""; StringBuffer pkFieldNames = new StringBuffer(); // get a list of all the primary key field names, walk through them List<String> pkFields = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(boClass); for (Iterator<String> iter = pkFields.iterator(); iter.hasNext(); ) { String pkFieldName = (String) iter.next(); // TODO should this be getting labels from the view dictionary // use the DataDictionary service to translate field name into human-readable label String humanReadableFieldName = ddService.getAttributeLabel(boClass, pkFieldName); // append the next field pkFieldNames.append(delim + humanReadableFieldName); // separate names with commas after the first one if (delim.equalsIgnoreCase("")) { delim = ", "; } } return pkFieldNames.toString(); }
/** * Returns a comma delimited list of primary key field labels, to be used on the UI to tell the user which fields were used to search * * These labels are generated from the DD definitions for the lookup fields * * @return a comma separated list of field attribute names. If no fields found, returns "N/A" * @see LookupableHelperService#isSearchUsingOnlyPrimaryKeyValues() * @see LookupableHelperService#getPrimaryKeyFieldLabels() */ @Override public String getPrimaryKeyFieldLabels() { StringBuilder buf = new StringBuilder(); List<String> primaryKeyFieldNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(getBusinessObjectClass()); Iterator<String> pkIter = primaryKeyFieldNames.iterator(); while (pkIter.hasNext()) { String pkFieldName = (String) pkIter.next(); buf.append(getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), pkFieldName)); if (pkIter.hasNext()) { buf.append(", "); } } return buf.length() == 0 ? KRADConstants.NOT_AVAILABLE_STRING : buf.toString(); }
/** * Retrieves the primary key property names for the given class. If the field's property is one of those keys, makes the field * read-only. This is called for collection lines. Since deletion is not allowed for existing lines, the pk fields must be * read-only, otherwise a user could change the pk value which would be equivalent to deleting the line and adding a new line. */ private static final void setPrimaryKeyFieldsReadOnly(Class businessObjectClass, Field field) { try{ //TODO: Revisit this. Changing since getPrimaryKeys and listPrimaryKeyFieldNames are apparently same. //May be we might want to replace listPrimaryKeyFieldNames with getPrimaryKeys... Not sure. List primaryKeyPropertyNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(businessObjectClass); if (primaryKeyPropertyNames.contains(field.getPropertyName())) { field.setReadOnly(true); } } catch(ClassNotPersistableException ex){ //Not all classes will be persistable in a collection. For e.g. externalizable business objects. LOG.info("Not persistable dataObjectClass: "+businessObjectClass+", field: "+field); } }
/** * This method clears the value of the primary key fields on a Business Object. * * @param document - document to clear the pk fields on */ protected void clearPrimaryKeyFields(MaintenanceDocument document) { // get business object being maintained and its keys PersistableBusinessObject bo = document.getNewMaintainableObject().getBusinessObject(); List<String> keyFieldNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(bo.getClass()); for (String keyFieldName : keyFieldNames) { try { ObjectUtils.setObjectProperty(bo, keyFieldName, null); } catch (Exception e) { LOG.error("Unable to clear primary key field: " + e.getMessage()); throw new RuntimeException("Unable to clear primary key field: " + e.getMessage()); } } bo.setObjectId(null); bo.setVersionNumber(new Long(1)); }
String attr = (String) iter.next(); Class clazz = (Class) referenceClasses.get(attr); List pkNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(clazz);
public Criteria getCollectionCriteriaFromMapUsingPrimaryKeysOnly(Class businessObjectClass, Map formProps) { BusinessObject businessObject = checkBusinessObjectClass(businessObjectClass); Criteria criteria = new Criteria(); List pkFields = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(businessObjectClass); Iterator pkIter = pkFields.iterator(); while (pkIter.hasNext()) { String pkFieldName = (String) pkIter.next(); String pkValue = (String) formProps.get(pkFieldName); if (StringUtils.isBlank(pkValue)) { throw new RuntimeException("Missing pk value for field " + pkFieldName + " when a search based on PK values only is performed."); } else { for (SearchOperator op : SearchOperator.QUERY_CHARACTERS) { if (pkValue.contains(op.op())) { throw new RuntimeException("Value \"" + pkValue + "\" for PK field " + pkFieldName + " contains wildcard/operator characters."); } } } boolean treatWildcardsAndOperatorsAsLiteral = KNSServiceLocator. getBusinessObjectDictionaryService().isLookupFieldTreatWildcardsAndOperatorsAsLiteral(businessObjectClass, pkFieldName); createCriteria(businessObject, pkValue, pkFieldName, false, treatWildcardsAndOperatorsAsLiteral, criteria); } return criteria; }
List<String> boPKeys = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(businessObjectClass); final List<List<String>> altKeys = this.getAltkeys(businessObjectClass);
List primaryKeys = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(gboClass); if (primaryKeys == null) { assumptionIsWrong = true;
List<String> keys = new ArrayList<String>(KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames( inquiryBusinessObjectClass));
List keyFieldNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(((MaintenanceDocumentBase) getDocument()).getNewMaintainableObject().getBusinessObject().getClass());
List<String> pkNames = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(getBusinessObjectClass()); Person user = GlobalVariables.getUserSession().getPerson();