/** * Retrieve the MutableProjectComponent with the specified ID. An EntityNotFoundException is thrown if the component * is not found. * * @param id component ID to search for * @return MutableProjectComponent component with the specified ID * @throws EntityNotFoundException if the component is not found */ public MutableProjectComponent find(Long id) throws EntityNotFoundException { validateId(id); GenericValue componentGV = findComponentGV(FIELD_ID, id); if (componentGV == null) { throw new EntityNotFoundException("Component with ID = '" + id + "' does not exist."); } else { return getComponentConverter().convertToComponent(componentGV); } }
/** * 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)); }
@Override public ProjectComponent getProjectComponent(final Long projectComponentId) { validateId(projectComponentId); GenericValue gv = findComponentGV(FIELD_ID, projectComponentId); if (gv == null) { return null; } else { return Entity.PROJECT_COMPONENT.build(gv); } }
validateProjectId(component); validateName(component); if (findComponentGV(FIELD_ID, component.getId()) == null)
public Collection<MutableProjectComponent> findByComponentNameCaseInSensitive(String componentName) { if (componentName == null) { throw new IllegalArgumentException("Component Name is required, was null."); } final Collection<MutableProjectComponent> components = getComponentConverter().convertToComponents(delegator.findAll(OfBizDelegator.PROJECT_COMPONENT)); List<MutableProjectComponent> matched = new ArrayList<MutableProjectComponent>(); for (MutableProjectComponent component : components) { if (componentName.equalsIgnoreCase(component.getName())) { matched.add(component); } } return matched; }
/** * 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)); }
/** * Retrieve the project ID for the given component ID. If project is not found, a EntityNotFoundException is * thrown. * * @param componentId component ID * @return project ID * @throws EntityNotFoundException if component not found for the given component ID */ public Long findProjectIdForComponent(Long componentId) throws EntityNotFoundException { GenericValue componentGV = findComponentGV(FIELD_ID, componentId); if (componentGV == null) { throw new EntityNotFoundException("Component with ID = '" + componentId + "' does not exist."); } else { return componentGV.getLong(FIELD_PROJECT); } }
/** * Retrieve all ProjectComponent objects stored and sort by name. * * @return all ProjectComponent objects stored */ public Collection findAll() { return getComponentConverter().convertToComponents(delegator.findAll(OfBizDelegator.PROJECT_COMPONENT, CollectionBuilder.list(FIELD_NAME))); }
/** * 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 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)); }
public MutableProjectComponent findByComponentName(Long projectId, String componentName) throws IllegalArgumentException { if (projectId == null) { throw new IllegalArgumentException("Project ID is required, was null."); } if (componentName == null) { throw new IllegalArgumentException("Component Name is required, was null."); } List components = delegator.findByAnd(OfBizDelegator.PROJECT_COMPONENT, MapBuilder.<String, Object>newBuilder().add(FIELD_PROJECT, projectId).add(FIELD_NAME, componentName).toMap()); // should only be one or none since component name is unique per project if (components.size() == 1) { return getComponentConverter().convertToComponent((GenericValue) components.get(0)); } else if (components.size() == 0) { return null; } else { log.error("found " + components.size() + " components with name " + componentName + " in project with id " + projectId); return (MutableProjectComponent) components.get(0); } }