/** *returns the values in the order specified * *@param values List of GenericValues *@param order The fields of the named entity to order the query by; * optionally add a " ASC" for ascending or " DESC" for descending *@return List of GenericValue's in the proper order */ public static List orderBy(List values, List orderBy) { if (values == null) return null; if (values.size() == 0) return UtilMisc.toList(values); List result = new ArrayList(values); Collections.sort(result, new OrderByComparator(orderBy)); return result; }
/** Gets a list of entity models that are in a group corresponding to the specified group name *@param groupName The name of the group *@return List of ModelEntity instances */ public List getModelEntitiesByGroup(String groupName) { Iterator enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); List entities = new LinkedList(); if (enames == null || !enames.hasNext()) return entities; while (enames.hasNext()) { String ename = (String) enames.next(); ModelEntity entity = this.getModelEntity(ename); if (entity != null) entities.add(entity); } return entities; }
private void setLegacyCloneDirectionProperty(boolean on) { final GenericValue propertyEntry = ofBizDelegator.createValue("OSPropertyEntry", UtilMisc.toMap("entityId", JIRA_PROPERTIES, "entityName", "jira.properties", "type", BOOLEAN, "propertyKey", UpgradeTask_Build849.JIRA_CLONE_LINK_LEGACY_DIRECTION)); ofBizDelegator.createValue("OSPropertyNumber", UtilMisc.toMap("id", propertyEntry.getLong("id"), "value", on ? 1 : 0)); }
private static Locale getLocale(HttpServletRequest request, HttpSession session) { Object localeObject = session != null ? session.getAttribute("locale") : null; if (localeObject == null) localeObject = request != null ? request.getLocale() : null; if (localeObject != null && localeObject instanceof String) { localeObject = UtilMisc.parseLocale((String) localeObject); } if (localeObject != null && localeObject instanceof Locale) { return (Locale) localeObject; } else { return Locale.getDefault(); } }
public static void setLocale(HttpServletRequest request, String localeString) { UtilHttp.setLocale(request, UtilMisc.parseLocale(localeString)); }
private void setLegacyCloneDirectionProperty(boolean on) { final GenericValue propertyEntry = ofBizDelegator.createValue("OSPropertyEntry", UtilMisc.toMap("entityId", JIRA_PROPERTIES, "entityName", "jira.properties", "type", BOOLEAN, "propertyKey", JIRA_CLONE_LINK_LEGACY_DIRECTION)); ofBizDelegator.createValue("OSPropertyNumber", UtilMisc.toMap("id", propertyEntry.getLong("id"), "value", on ? 1 : 0)); }
/** Gets a list of entity models that are in a group corresponding to the specified group name *@param groupName The name of the group *@return List of ModelEntity instances */ public List getModelEntitiesByGroup(String groupName) { Iterator enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); List entities = new LinkedList(); if (enames == null || !enames.hasNext()) return entities; while (enames.hasNext()) { String ename = (String) enames.next(); ModelEntity entity = this.getModelEntity(ename); if (entity != null) entities.add(entity); } return entities; }
/** * returns the values in the order specified * * @param values List of GenericValues * @param order The fields of the named entity to order the query by; * optionally add a " ASC" for ascending or " DESC" for descending * @return List of GenericValue's in the proper order */ public static <T extends GenericValue> List<T> orderBy(List<T> values, List<String> orderBy) { if (values == null) return null; if (values.size() == 0) return UtilMisc.toList(values); List<T> result = new ArrayList<T>(values); Collections.sort(result, new OrderByComparator(orderBy)); return result; }
return value; } else if ("Locale".equals(type) || "java.util.Locale".equals(type)) { Locale loc = UtilMisc.parseLocale(str); if (loc != null) { return loc;
@Override public GenericPK getPrimaryKey() { return new GenericPK(getModelEntity(), UtilMisc.toMap("id", fields.get("id"))); }
/** * Gets a list of entity models that are in a group corresponding to the specified group name. * * @param groupName The name of the group * @return List of ModelEntity instances */ public List<ModelEntity> getModelEntitiesByGroup(final String groupName) { checkIfLocked(); final Iterator<String> enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); final List<ModelEntity> entities = new LinkedList<ModelEntity>(); if (enames == null || !enames.hasNext()) return entities; while (enames.hasNext()) { String ename = enames.next(); ModelEntity entity = getModelEntity(ename); if (entity != null) entities.add(entity); } return entities; }
/** *returns the values in the order specified * *@param values List of GenericValues *@param order The fields of the named entity to order the query by; * optionally add a " ASC" for ascending or " DESC" for descending *@return List of GenericValue's in the proper order */ public static List orderBy(List values, List orderBy) { if (values == null) return null; if (values.size() == 0) return UtilMisc.toList(values); List result = new ArrayList(values); Collections.sort(result, new OrderByComparator(orderBy)); return result; }
return value; } else if ("Locale".equals(type) || "java.util.Locale".equals(type)) { Locale loc = UtilMisc.parseLocale(str); if (loc != null) { return loc;
private GenericValue getAssociation(String sourceNodeEntity, Long sourceNodeId, String sinkNodeEntity, Long sinkNodeId, String associationType) { return EntityUtil.getOnly(ofBizDelegator.findByAnd("NodeAssociation", UtilMisc.toMap("associationType", associationType, "sourceNodeId", sourceNodeId, "sourceNodeEntity", sourceNodeEntity, "sinkNodeId", sinkNodeId, "sinkNodeEntity", sinkNodeEntity))); } }
/** Gets a Map of entity name & entity model pairs that are in the named group *@param groupName The name of the group *@return Map of entityName String keys and ModelEntity instance values */ public Map getModelEntityMapByGroup(String groupName) { Iterator enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); Map entities = new HashMap(); if (enames == null || !enames.hasNext()) { return entities; } int errorCount = 0; while (enames.hasNext()) { String ename = (String) enames.next(); try { ModelEntity entity = getModelReader().getModelEntity(ename); if (entity != null) { entities.put(entity.getEntityName(), entity); } else { throw new IllegalStateException("Programm Error: entity was null with name " + ename); } } catch (GenericEntityException ex) { errorCount++; Debug.logError("Entity " + ename + " named in Entity Group with name " + groupName + " are not defined in any Entity Definition file"); } } if (errorCount > 0) { Debug.logError(errorCount + " entities were named in ModelGroup but not defined in any EntityModel"); } return entities; }
private List<GenericValue> getAssociations(String associationName, Map<String, Object> fields, boolean useSequence) throws DataAccessException { List<GenericValue> result; result = ofBizDelegator.findByAnd(associationName, fields); if (result == null) return emptyList(); if (useSequence) { result = EntityUtil.orderBy(result, UtilMisc.toList("sequence")); } return result; }
@SuppressWarnings("unchecked") protected Map<String, ?> makeParameterMap(final KeyAssociations associations, final Project project) { return UtilMisc.toMap("name", getApplication().toString().toLowerCase(), "associations", associations, "id", project.getId()); }
/** Gets a Map of entity name & entity model pairs that are in the named group *@param groupName The name of the group *@return Map of entityName String keys and ModelEntity instance values */ public Map getModelEntityMapByGroup(String groupName) { Iterator enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); Map entities = new HashMap(); if (enames == null || !enames.hasNext()) { return entities; } int errorCount = 0; while (enames.hasNext()) { String ename = (String) enames.next(); try { ModelEntity entity = getModelReader().getModelEntity(ename); if (entity != null) { entities.put(entity.getEntityName(), entity); } else { throw new IllegalStateException("Programm Error: entity was null with name " + ename); } } catch (GenericEntityException ex) { errorCount++; Debug.logError("Entity " + ename + " named in Entity Group with name " + groupName + " are not defined in any Entity Definition file"); } } if (errorCount > 0) { Debug.logError(errorCount + " entities were named in ModelGroup but not defined in any EntityModel"); } return entities; }
@Override public List<MailServer> get() { try { List<GenericValue> mailServerGVs = ComponentAccessor.getOfBizDelegator().findAll("MailServer", UtilMisc.toList("id asc")); return ImmutableList.copyOf(Iterables.transform(mailServerGVs, new Function<GenericValue, MailServer>() { @Override public MailServer apply(GenericValue from) { return constructMailServer(from); } })); } catch (DataAccessException e) { throw new RuntimeException(e); } } }
protected GenericValue getMailServerGV(Long id) throws MailException { try { return ComponentAccessor.getOfBizDelegator().findByPrimaryKey("MailServer", UtilMisc.toMap("id", id)); } catch (DataAccessException e) { throw new MailException(e); } }