/** * Retrieve the unique GenericValue object that has a field of specified name set to the specified value. The * GenericValue returned should be unique. * * @param fieldName field name to search by * @param fieldValue field value searched for * @return the unqiue GenericValue */ private GenericValue findComponentGV(String fieldName, Object fieldValue) { return EntityUtil.getOnly(findComponentGVs(fieldName, fieldValue)); }
/** * Check whether component with specified name is stored. * * @param name component name, null will cause IllegalArgumentException * @param projectId project ID * @return true if new name is stored * @throws IllegalArgumentException if name or projectId is null */ public boolean containsName(String name, Long projectId) { if (projectId == null) { throw new IllegalArgumentException("Component project ID can not be null!"); } if (name == null) { throw new IllegalArgumentException("Component name can not be null!"); } Collection<GenericValue> componentsForProject = findComponentGVs(FIELD_PROJECT, projectId); for (final GenericValue componentGV : componentsForProject) { if (name.equalsIgnoreCase(componentGV.getString("name"))) { return true; } } return false; }
/** * Retrieve a collection of components - where the lead of each component is the specified user. * * @param userKey the lead user's key * @return collection of components - where the lead of each component is the specified user */ public Collection findComponentsBylead(String userKey) { return getComponentConverter().convertToComponents(findComponentGVs(FIELD_LEAD, userKey)); }
/** * Retrieve all components that are related to the project with given ID and sort by name. * * @param projectId project ID * @return a collection of ProjectComponent objects that are related to the project with given ID */ public Collection<MutableProjectComponent> findAllForProject(Long projectId) { return getComponentConverter().convertToComponents(findComponentGVs(FIELD_PROJECT, projectId,FIELD_NAME)); }