private String getCommentHtml(Issue issue, Action action) { final OperationContext context = (OperationContext) action; final MapBuilder<String, Object> displayParams = MapBuilder.newBuilder(); displayParams.add("theme", "aui"); displayParams.add("noHeader", true); final FieldLayout fieldLayout = fieldLayoutManager.getFieldLayout(issue); final FieldLayoutItem commentFieldLayoutItem = fieldLayout.getFieldLayoutItem("comment"); final OrderableField commentField = commentFieldLayoutItem.getOrderableField(); return commentField.getCreateHtml( commentFieldLayoutItem, context, action, issue, displayParams.toMap()); }
private String getViewHtmlForId( Issue baseIssue, final FieldLayoutItem fieldLayoutItem, OrderableField field, Long id, final boolean showProject) { // -1 means no value if (id == null || id == -1L) { return getText("common.words.unknown"); } // dummy up the value for an issue Object value; if (field instanceof CustomField) { value = getValueForId((CustomField) field, id); } else { value = getValueForId(field, id); } // set the value in a field values holder final Map<String, Object> fieldValuesHolder = new LinkedHashMap<String, Object>(); fieldValuesHolder.put(field.getId(), value); // update an issue with these values final MutableIssue dummyIssue = issueFactory.cloneIssue(baseIssue); field.updateIssue(fieldLayoutItem, dummyIssue, fieldValuesHolder); // now render the field if (showProject) { return field.getViewHtml( fieldLayoutItem, this, dummyIssue, MapBuilder.singletonMap("showProject", true)); } else { return field.getViewHtml(fieldLayoutItem, this, dummyIssue); } }
public void doUpgrade(boolean setupMode) throws Exception { // find all portalpages that have no version set yet. final OfBizListIterator iterator = delegator.findListIteratorByCondition( OfBizPortalPageStore.Table.NAME, new EntityExpr(OfBizPortalPageStore.Column.VERSION, EntityOperator.EQUALS, null)); final List<Long> portalPageIds = new ArrayList<Long>(); try { GenericValue portalPageGv = iterator.next(); while (portalPageGv != null) { portalPageIds.add(portalPageGv.getLong(OfBizPortalPageStore.Column.ID)); portalPageGv = iterator.next(); } } finally { iterator.close(); } try { // set version to 0 for all dashboard pages returned by the previous query. final int rowsUpdated = delegator.bulkUpdateByPrimaryKey( OfBizPortalPageStore.Table.NAME, MapBuilder.<String, Object>newBuilder() .add(OfBizPortalPageStore.Column.VERSION, 0L) .toMap(), portalPageIds); log.info("Initialised " + rowsUpdated + " dashboard versions to 0."); } finally { portalPageStore.flush(); } }
@Test public void testGetSearchClauseOneProjectIsFlag() throws Exception { final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl(); customFieldParams.addValue(Collections.singleton("123")); final Map<String, Object> map = MapBuilder.<String, Object>newBuilder() .add(urlParameterName, customFieldParams) .add( SystemSearchConstants.forProject().getUrlParameter(), Collections.singletonList("-1")) .toMap(); FieldValuesHolder values = new FieldValuesHolderImpl(map); final AtomicBoolean specialCalled = new AtomicBoolean(false); final IndexedInputHelper helper = new DefaultIndexedInputHelper<Version>( indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker) { @Override public Clause getClauseForNavigatorValues(final String clauseName, final Set values) { return null; } }; transformer = new VersionCustomFieldSearchInputTransformer( urlParameterName, clauseNames, customField, indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager) { @Override protected DefaultIndexedInputHelper getDefaultIndexedInputHelper() { throw new UnsupportedOperationException( "Should not have called through to the special indexed input helper"); } @Override protected IndexedInputHelper getIndexedInputHelper() { specialCalled.set(true); return helper; } @Override protected String getClauseName(final User searcher, final ClauseNames clauseNames) { return primaryClauseName; } }; replay(); transformer.getSearchClause(theUser, values); assertTrue(specialCalled.get()); }
public String getNewViewHtml(OrderableField field) { final Map displayParameters = MapBuilder.newBuilder("readonly", Boolean.TRUE).add("nolink", Boolean.TRUE).toMap(); return field.getViewHtml( getBulkEditBean().getTargetFieldLayout().getFieldLayoutItem(field), this, getBulkEditBean().getFirstTargetIssueObject(), displayParameters); }
@Override public void update( Comment comment, Map<String, JSONObject> commentProperties, boolean dispatchEvent) { if (comment == null) { throw new IllegalArgumentException("Comment must not be null"); } if (comment.getId() == null) { throw new IllegalArgumentException("Comment ID must not be null"); } // create persistable generic value GenericValue commentGV; // We need an in-memory copy of the old comment so we can pass it through in the fired event and // to make sure // that some fields have changed. Comment originalComment = getCommentById(comment.getId()); if (originalComment == null) { throw new IllegalArgumentException( "Can not find a comment in the datastore with id: " + comment.getId()); } // Make sure that either the comment body or visibility data has changed, otherwise do not // update the datastore if (!areCommentsEquivalent(originalComment, comment)) { try { commentGV = delegator.findById(COMMENT_ENTITY, comment.getId()); populateGenericValueFromComment(comment, commentGV); commentGV.store(); } catch (GenericEntityException e) { throw new DataAccessException(e); } // Update the issue object IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class); GenericValue issueGV = comment.getIssue().getGenericValue(); MutableIssue mutableIssue = issueFactory.getIssue(issueGV); mutableIssue.setUpdated(UtilDateTime.nowTimestamp()); mutableIssue.store(); } // Update comment properties if (commentProperties != null) { setProperties(comment.getAuthorApplicationUser(), comment, commentProperties); } // Dispatch an event if required if (dispatchEvent) { dispatchIssueCommentEditedEvent( comment, MapBuilder.build( "eventsource", IssueEventSource.ACTION, EVENT_ORIGINAL_COMMENT_PARAMETER, originalComment)); } }
@Override public void run() { boolean resultingFromCacheClearEvent = false; if (!resultingFromCacheClearEvent) { log.debug("Flushing JIRA memory caches"); final Map<String, Boolean> props = MapBuilder.build(SERVICE_EVENT, true); ComponentAccessor.getComponent(EventPublisher.class).publish(new ClearCacheEvent(props)); } }
@Override public Map<String, Object> getContextMap(Map<String, Object> context) { final Issue issue = (Issue) context.get("issue"); final Action action = (Action) context.get("action"); Map<String, Object> paramsBuilder = MapBuilder.newBuilder(context).toMutableMap(); paramsBuilder.put("commentHtml", getCommentHtml(issue, action)); return paramsBuilder; }
@Test public void testGetClauseFromParamsValuesGetFiltered() throws Exception { final String clauseName = "clauseName"; final CustomField customField = mockController.getMock(CustomField.class); EasyMock.expect(customField.getName()).andStubReturn("ABC"); EasyMock.expect(customFieldInputHelper.getUniqueClauseName(theUser, clauseName, "ABC")) .andStubReturn(clauseName); final CustomFieldParamsImpl customFieldParams = new CustomFieldParamsImpl(); customFieldParams.addValue(CollectionBuilder.newBuilder("55", "-1", "").asMutableSet()); final Set<String> expectedFilteredValues = CollectionBuilder.newBuilder("55").asMutableSet(); final Clause expectedClause = mockController.getMock(Clause.class); final IndexedInputHelper indexedInputHelper = mockController.getMock(IndexedInputHelper.class); indexedInputHelper.getClauseForNavigatorValues(clauseName, expectedFilteredValues); mockController.setReturnValue(expectedClause); transformer = new VersionCustomFieldSearchInputTransformer( clauseName, new ClauseNames(clauseName), customField, indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager) { @Override IndexedInputHelper getIndexedInputHelper() { return indexedInputHelper; } @Override boolean isVersionsNotRelatedToProjects( final Set<String> versionIdsFromHolder, final FieldValuesHolder fieldValuesHolder) { return false; } }; mockController.replay(); FieldValuesHolder holderValues = new FieldValuesHolderImpl(MapBuilder.singletonMap(urlParameterName, customFieldParams)); assertEquals( expectedClause, transformer.getClauseFromParams(theUser, customFieldParams, holderValues)); mockController.verify(); }
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(); } }
static DbIndependentMockGenericValue createIssueGV( Long id, Long projectId, String summary, String key, String assignee, String resolution) { return new DbIndependentMockGenericValue( "Issue", MapBuilder.<String, Object>newBuilder() .add("id", id) .add("project", projectId) .add("assignee", assignee) .add("summary", summary) .add("key", key) .add("resolution", resolution) .toMap()); }
public String getNewViewHtml(BulkEditBean bulkEditBean, OrderableField field) { final Map<String, Object> displayParameters = MapBuilder.<String, Object>newBuilder("readonly", Boolean.TRUE) .add("nolink", Boolean.TRUE) .add( "prefix", bulkEditBean.getProject().getString("id") + "_" + bulkEditBean.getIssueType().getString("id") + "_") .toMap(); return field.getViewHtml( bulkEditBean.getTargetFieldLayout().getFieldLayoutItem(field), this, bulkEditBean.getFirstTargetIssueObject(), displayParameters); }
public String getFieldViewHtml(OrderableField orderableField) { final Map<String, Object> displayParams = MapBuilder.<String, Object>newBuilder("readonly", Boolean.TRUE) .add("nolink", Boolean.TRUE) .add("bulkoperation", getBulkEditBean().getOperationName()) .toMutableMap(); // Use the layout item of where we are going since we are moving to that space FieldLayoutItem layoutItem = getBulkEditBean().getTargetFieldLayout().getFieldLayoutItem(orderableField); return orderableField.getViewHtml( layoutItem, this, getBulkEditBean().getFirstTargetIssueObject(), getBulkEditBean().getFieldValues().get(orderableField.getId()), displayParams); }
@Test public void testGetSearchClauseNoNavigatorValues() throws Exception { FieldValuesHolder values = new FieldValuesHolderImpl(MapBuilder.emptyMap()); transformer = new VersionCustomFieldSearchInputTransformer( urlParameterName, clauseNames, customField, indexInfoResolver, operandResolver, fieldFlagOperandRegistry, searchContextVisibilityChecker, versionResolver, customFieldInputHelper, versionManager); replay(); final Clause result = transformer.getSearchClause(theUser, values); assertNull(result); }