/** * Checks whether component with specified name is stored. * * @param name component name, null will cause IllegalArgumentException * @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<ProjectComponent> components = projectIdToComponentsMap.get(projectId); return containsNameIgnoreCase(components, name); }
/** * Finds one or more ProjectComponent with a given name. * * @param componentName the name of the component to find. * @return a Collection of Components with the given name. */ public Collection<MutableProjectComponent> findByComponentNameCaseInSensitive(String componentName) { Collection<MutableProjectComponent> components = findAll(); Collection<MutableProjectComponent> matchingComponents = new ArrayList<MutableProjectComponent>(); for (final MutableProjectComponent component : components) { if (component.getName().equalsIgnoreCase(componentName)) { matchingComponents.add(component); } } return matchingComponents; }
/** * Persist the component. If component has no ID (null) it is inserted to the database and added to the cache, * otherwise an update operation is performed on both cache and database. * * @param component component to persist * @throws EntityNotFoundException in case of update if the component does not exist (maybe was deleted :-) * @throws com.atlassian.jira.exception.DataAccessException if cannot persist the component */ public MutableProjectComponent store(MutableProjectComponent component) throws EntityNotFoundException, DataAccessException { MutableProjectComponent copy = MutableProjectComponent.copy(component); MutableProjectComponent newComponent; if (copy.getId() == null) { newComponent = insert(copy); } else { newComponent = update(copy); } return newComponent; }
try MutableProjectComponent old = find(component.getId()); if (!old.equalsName(component)) if (containsName(component.getName(), component.getProjectId())) updateCache(component); return component;
if (containsName(name, component.getProjectId())) throw createIllegalArgumentExceptionForName(name);
/** * Looks up the component with the given name in the project with the given id. * * @param projectId id of the project. * @param componentName name of the component. * @return the component. * @throws EntityNotFoundException if no such component can be found. */ public MutableProjectComponent findByComponentName(Long projectId, String componentName) throws EntityNotFoundException { Collection<MutableProjectComponent> components = findAllForProject(projectId); for (MutableProjectComponent c : components) { if (c.getName().equals(componentName)) { return c; } } throw new EntityNotFoundException("The project with id '" + projectId + "' is not associated with a component with the name '" + componentName + "'."); }
/** * Retrieves all ProjectComponents that have the given user as their lead. * Not synchronised, because findAll() returns a private copy of all components. * * @param userKey key of the lead user * @return possibly empty Collection of ProjectComponents. */ public Collection findComponentsBylead(String userKey) { Collection<ProjectComponent> leadComponents = new ArrayList<ProjectComponent>(); Collection components = findAll(); for (final Object component : components) { MutableProjectComponent projectComponent = (MutableProjectComponent) component; if (projectComponent != null && TextUtils.stringSet(projectComponent.getLead()) && projectComponent.getLead().equals(userKey)) { leadComponents.add(projectComponent); } } return leadComponents; }