private GenericValue newChangeItem(String field, String newValue) { GenericValue changeItem = mock(GenericValue.class); when(changeItem.getString("field")).thenReturn(field); when(changeItem.getString("newvalue")).thenReturn(newValue); when(changeItem.getString("newstring")).thenReturn(newValue); return changeItem; }
// Ensure that the filter subscriptions table does not contain references to search requests that // have been deleted. protected void doRealCheck( boolean correct, GenericValue subscription, List<DeleteEntityAmendment> messages) throws IntegrityException { // try to find the related quartz trigger, if null then flag JobDetails jobDetails = getScheduledJob(subscription); if (jobDetails == null) { if (correct) { // flag the current subscription for deletion messages.add( new DeleteEntityAmendment( Amendment.CORRECTION, getI18NBean() .getText( "admin.integrity.check.filter.subscriptions.trigger.message", subscription.getString("id")), subscription)); } else { messages.add( new DeleteEntityAmendment( Amendment.ERROR, getI18NBean() .getText( "admin.integrity.check.filter.subscriptions.trigger.preview", subscription.getString("id")), subscription)); } } }
@Test public void testUpdateProjectCategory() throws GenericEntityException { projectCategory.set("name", "A New Name"); projectCategory.set("description", "A New Description"); testedObject.updateProjectCategory(projectCategory); final GenericValue retrievedProjectCat = testedObject.getProjectCategory(projectCategory.getLong("id")); assertEquals("A New Name", retrievedProjectCat.getString("name")); assertEquals("A New Description", retrievedProjectCat.getString("description")); }
private List doCheck(boolean correct) throws IntegrityException { List results = new ArrayList(); String message; List filtersToRemove = new ArrayList(); OfBizListIterator listIterator = null; try { listIterator = ofBizDelegator.findListIteratorByCondition("SearchRequest", null); GenericValue filter = (GenericValue) listIterator.next(); while (filter != null) { if (TextUtils.stringSet(filter.getString("project"))) { if (ofBizDelegator.findById("Project", filter.getLong("project")) == null) { if (correct) { message = getI18NBean() .getText( "admin.integrity.check.search.request.relation.check.message", filter.getString("name")); results.add(new CheckAmendment(Amendment.ERROR, message, "JRA-2279")); filtersToRemove.add(filter); } else { message = getI18NBean() .getText( "admin.integrity.check.search.request.relation.check.preview", filter.getString("name")); results.add(new CheckAmendment(Amendment.ERROR, message, "JRA-2279")); } } } filter = (GenericValue) listIterator.next(); } } finally { if (listIterator != null) { // Close the iterator listIterator.close(); } } if (correct && !filtersToRemove.isEmpty()) { try { ofBizDelegator.removeAll(filtersToRemove); } catch (DataAccessException e) { throw new IntegrityException(e); } } return results; }
// I have found no way of unit testing GenericValues private Collection<String> genericValueToString(Collection<GenericValue> values, String field) { Collection<String> comps = new ArrayList<String>(); for (GenericValue ge : values) { comps.add(ge.getString(field)); } return comps; }
private void migrateFeatures(String featureType) throws GenericEntityException { GenericValue sourcePropertyGV = getPropertyGV(Table.ENTRY, Column.KEY, featureType); if (sourcePropertyGV != null) { long entityId = sourcePropertyGV.getLong(Column.ENTITY_ID); long id = sourcePropertyGV.getLong(Column.ID); GenericValue sourceFeatureGV = ofBizDelegator.findById(Table.STRING, id); if (sourceFeatureGV != null) { Set<String> sourceFeatures = deserialize(sourceFeatureGV.getString(Column.VALUE)); sourceFeatureGV.remove(); for (String feature : sourceFeatures) { MapBuilder<String, Object> propertyMapBuilder = MapBuilder.newBuilder(); propertyMapBuilder.add(Column.FEATURE_NAME, feature); propertyMapBuilder.add(Column.FEATURE_TYPE, getFeatureType(featureType)); propertyMapBuilder.add(Column.USERKEY, getUserKey(featureType, entityId)); final Map<String, Object> featureMap = propertyMapBuilder.toMap(); if (featureNotPresent(featureMap)) { ofBizDelegator.createValue(Table.FEATURE, featureMap); } } } sourcePropertyGV.remove(); } }
/** Given a collection of entities, return an array of Strings representing the IDs */ public static String[] getStringArrayFromList(Collection entities) { String[] ar = new String[entities.size()]; int i = 0; for (Iterator iterator = entities.iterator(); iterator.hasNext(); i++) { GenericValue genericValue = (GenericValue) iterator.next(); ar[i] = genericValue.getString("id"); } return ar; }
private String getUserKey(String featureType, long entityId) { if (featureType.equals(USER_FEATURES)) { GenericValue usergv = ofBizDelegator.findById(Table.APPLICATION_USER, entityId); if (usergv != null) { return usergv.getString(Column.USERKEY); } } return null; }
public void testGetScheme() throws CreateException, GenericEntityException { setupSchemes(); assertTrue(issueSchemeManager.getSchemes().size() == 1); assertTrue(issueSchemeManager.getSchemes(project).size() == 1); assertNotNull(issueSchemeManager.getScheme(issueScheme.getLong("id"))); assertNotNull(issueSchemeManager.getScheme(issueScheme.getString("name"))); assertTrue(issueSchemeManager.getSchemes(project2).size() == 0); }
public Collection getAddableIssueTypes() { if (addableIssueTypes == null) { addableIssueTypes = new LinkedList(getAllRelevantIssueTypeObjects()); for (Iterator iterator = addableIssueTypes.iterator(); iterator.hasNext(); ) { IssueType issueType = (IssueType) iterator.next(); GenericValue issueTypeGV = issueType.getGenericValue(); if (getFieldLayoutScheme().getEntity(issueTypeGV.getString("id")) != null) { iterator.remove(); } } } return addableIssueTypes; }
public void testaddOldGlobalPermissionsToScheme() throws Exception { GenericValue scheme = psm.createScheme("test", "test"); EntityUtils.createValue( "Permission", EasyMap.build("project", null, "type", new Long(99), "group", "test")); task.addOldGlobalPermissionsToScheme(psm, 99, scheme); assertNotNull(psm.getScheme("test")); List perms = psm.getEntities(scheme, new Long(99), "test"); assertTrue(perms.size() > 0); assertTrue(perms.size() == 1); GenericValue p = (GenericValue) perms.get(0); assertEquals(p.getString("parameter"), "test"); }
public Collection getAllIssueTypes() throws Exception { if (subTaskManager.isSubTasksEnabled()) { return constantsManager.getAllIssueTypeObjects(); } else { final ArrayList returnValues = new ArrayList(constantsManager.getRegularIssueTypeObjects()); // Now, since subtasks are disabled we want to make sure we add any subtask issue types that // are already // selected in the custom field and make sure that the sort order is the same as when we call // getAllIssueTypeObjects final List intersection = new ArrayList( CollectionUtils.intersection( constantsManager.getSubTaskIssueTypes(), getCustomField().getAssociatedIssueTypes())); Collections.sort(intersection); for (final Object anIntersection : intersection) { final GenericValue genericValue = (GenericValue) anIntersection; returnValues.add(0, constantsManager.getIssueTypeObject(genericValue.getString("id"))); } return returnValues; } }
protected GenericValue getConstant(GenericValue i1) { return ManagerFactory.getConstantsManager().getIssueType(i1.getString("type")); }
protected String getSearchValue(Object value) { GenericValue project = (GenericValue) value; return project.getString("id"); }
@Override @RequiresXsrfCheck protected String doExecute() throws Exception { if (isFieldLocked()) { return "locked"; } FieldConfigScheme configScheme = new FieldConfigScheme.Builder(getConfig()) .setName(getName()) .setDescription(getDescription()) .toFieldConfigScheme(); if (isBasicMode()) { // Add the contexts final List<JiraContextNode> contexts = CustomFieldUtils.buildJiraIssueContexts( isGlobal(), getProjectCategories(), getProjects(), treeManager); // Add the issue types final List<GenericValue> issueTypes = CustomFieldUtils.buildIssueTypes(constantsManager, getIssuetypes()); boolean messageRequired; if (configScheme.getId() == null) { messageRequired = customFieldContextConfigHelper.doesAddingContextToCustomFieldAffectIssues( getLoggedInUser(), getCustomField(), contexts, issueTypes, false); configScheme = fieldConfigSchemeManager.createFieldConfigScheme( configScheme, contexts, issueTypes, getCustomField()); } else { // keep a handle on the old scheme (pre edit) projects and issue types messageRequired = customFieldContextConfigHelper.doesChangingContextAffectIssues( getLoggedInUser(), getCustomField(), configScheme, isGlobal(), contexts, issueTypes); // Update so keep the old config if (issueTypes != null) { // Since we know that there is only one config final Long configId = getFieldConfigIds()[0]; final FieldConfig config = fieldConfigManager.getFieldConfig(configId); final Map<String, FieldConfig> configs = new HashMap<String, FieldConfig>(issueTypes.size()); for (final GenericValue issueType : issueTypes) { final String issueTypeId = issueType == null ? null : issueType.getString(FieldConfigSchemePersisterImpl.ENTITY_ID); configs.put(issueTypeId, config); } configScheme = new FieldConfigScheme.Builder(configScheme).setConfigs(configs).toFieldConfigScheme(); } configScheme = fieldConfigSchemeManager.updateFieldConfigScheme( configScheme, contexts, getCustomField()); } if (messageRequired) { reindexMessageManager.pushMessage( getLoggedInUser(), "admin.notifications.task.custom.fields"); } fieldConfigScheme = configScheme; } else { // @TODO advanced config } ComponentAccessor.getFieldManager().refresh(); customFieldManager.refreshConfigurationSchemes(getCustomFieldId()); return redirectToView(); }