Skip to content

Commit

Permalink
Merge pull request #5 from jazz-community/improved-state-type-mapping
Browse files Browse the repository at this point in the history
Improved State Mapping
  • Loading branch information
innerjoin authored Dec 8, 2017
2 parents 67e8072 + d3907fb commit 2a8b00c
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 95 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This section contains the API definition for this project. While we try to do ou
### base path
You'll see the term `<root>` within the following API doc a few times. It represents the root (or base) path for this service. Assuming that your CCM server is being referred to as `localhost:7443/ccm`, the `<root>` path for this service is the following:

> https://localhost:7443/ccm/service/com.siemens.bt.jazz.services.WorkItemBulkMover.IWorkItemBulkMoverService
> https://localhost:7443/jazz/service/com.siemens.bt.jazz.services.WorkItemBulkMover.IWorkItemBulkMoverService
### get project area
List all available project areas.
Expand Down
2 changes: 1 addition & 1 deletion feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="com.siemens.bt.jazz.services.WorkItemBulkMover.feature"
label="REST Service"
version="1.1.2.qualifier"
version="1.2.0.qualifier"
provider-name="PROVIDER">

<description url="http://www.example.com/description">
Expand Down
2 changes: 1 addition & 1 deletion feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.siemens.bt.jazz.services.WorkItemBulkMover</groupId>
<artifactId>com.siemens.bt.jazz.services.WorkItemBulkMover.parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.siemens.bt.jazz.services.WorkItemBulkMover
Bundle-SymbolicName: com.siemens.bt.jazz.services.WorkItemBulkMover;singleton:=true
Bundle-Version: 1.1.2.qualifier
Bundle-Version: 1.2.0.qualifier
Bundle-Vendor: VENDOR
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle:
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.siemens.bt.jazz.services.WorkItemBulkMover</groupId>
<artifactId>com.siemens.bt.jazz.services.WorkItemBulkMover.parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ibm.team.jfs.app.http.util.HttpConstants.HttpMethod;
import com.siemens.bt.jazz.services.WorkItemBulkMover.services.MoveService;
import com.siemens.bt.jazz.services.WorkItemBulkMover.services.ProjectAreaService;
import com.siemens.bt.jazz.services.WorkItemBulkMover.services.ProjectAreaTypeService;
import com.siemens.bt.jazz.services.base.BaseService;
import com.siemens.bt.jazz.services.base.router.factory.RestFactory;

Expand All @@ -11,5 +12,6 @@ public WorkItemBulkMoverService() {
super();
router.addService(HttpMethod.POST, "move", new RestFactory(MoveService.class));
router.addService(HttpMethod.GET, "project-areas", new RestFactory(ProjectAreaService.class));
router.addService(HttpMethod.GET, "types", new RestFactory(ProjectAreaTypeService.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public WorkItemMover(TeamRawService parentService) {
* @throws URISyntaxException
*/
@SuppressWarnings("restriction")
public MovePreparationResult PrepareMove(List<IWorkItem> sourceWorkItems, IProjectAreaHandle targetArea, Collection<AttributeDefinition> mappingDefinitions) throws UnsupportedEncodingException, TeamRepositoryException, URISyntaxException {
public MovePreparationResult PrepareMove(List<IWorkItem> sourceWorkItems, IProjectAreaHandle targetArea, Collection<AttributeDefinition> mappingDefinitions, Map<String, String> typeMap) throws UnsupportedEncodingException, TeamRepositoryException, URISyntaxException {
// run the bulk movement operation
BulkMoveOperation oper = new BulkMoveOperation(targetArea, service);
oper.run(sourceWorkItems, workItemServer, monitor);
Expand All @@ -90,6 +90,14 @@ public MovePreparationResult PrepareMove(List<IWorkItem> sourceWorkItems, IProje
if(workItems.size() == 0) {
throw new TeamRepositoryException("No work Items found to move. This likely happens if Source and Targer project area are the same");
}

// update work item type according to client mapping
for(WorkItemMoveMapper entry : workItems) {
String sourceType = entry.getSourceWorkItem().getWorkItemType();
String targetType = typeMap.get(sourceType);
WorkItemTypeHelpers.setWorkItemType(entry.getSourceWorkItem(), entry.getTargetWorkItem(), sourceType, targetType, workItemServer, monitor);
}

if(mappingDefinitions != null && mappingDefinitions.size() > 0) {
// if the user has sent mappings for specific attributes, apply them now
applyMappingsToWorkItems(workItems, mappingDefinitions);
Expand Down Expand Up @@ -203,7 +211,6 @@ private void addWorkItemToAttributeDefinitions(AttributeDefinitions attributeDef
&& !AttributeHelpers.IGNORED_ATTRIBUTES.contains(targetAttr.getIdentifier())) {
if(!attributeDefinitions.contains(sourceAttr.getIdentifier())) {
AttributeDefinition definition = new AttributeDefinition(targetAttr.getIdentifier(), targetAttr.getDisplayName());
definition.addAllowedValues(attributeHelpers.getAvailableOptionsPresentations(targetAttr, targetWorkItem));
attributeDefinitions.add(definition);
}
AttributeDefinition definition = attributeDefinitions.get(sourceAttr.getIdentifier());
Expand All @@ -212,8 +219,11 @@ private void addWorkItemToAttributeDefinitions(AttributeDefinitions attributeDef
WorkItem wi = new WorkItem(sourceWorkItem.getId(), sourceWorkItem.getHTMLSummary().getPlainText(), null);
boolean isRequired = requiredAttributes.contains(targetAttr.getIdentifier());
if(mapping == null) {
definition.addValueMapping(new MappingDefinition(
oldAttributeValue, new AffectedWorkItem(wi, isRequired)));
MappingDefinition def = new MappingDefinition(
oldAttributeValue, new AffectedWorkItem(wi, isRequired));
definition.addValueMapping(def);
List<AttributeValue> val = attributeHelpers.getAvailableOptionsPresentations(targetAttr, targetWorkItem);
def.addAllowedValues(val);
} else {
mapping.addAffectedWorkItem(wi, isRequired);
}
Expand All @@ -222,7 +232,6 @@ private void addWorkItemToAttributeDefinitions(AttributeDefinitions attributeDef
}
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public AttributeHelpers(TeamRawService teamRawService, IWorkItemServer workItemS
IWorkItem.COMMENTS_PROPERTY,
// custom attributes are not moveable if they do not exist in the target area
IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY,
// type is already processed before
IWorkItem.TYPE_PROPERTY,
// the following attributes are automatically tracked by the server itself
IWorkItem.CONTEXT_ID_PROPERTY,
IItem.ITEM_ID_PROPERTY,
Expand All @@ -56,9 +58,7 @@ public void setAttributeForWorkItem(IWorkItem sourceWorkItem, IWorkItem targetWo
Identifier<IAttribute> identifier = WorkItemAttributes.getPropertyIdentifier(attribute.getIdentifier());

if(valueId != null) {
if (WorkItemAttributes.TYPE.equals(identifier)) {
WorkItemTypeHelpers.setWorkItemType(sourceWorkItem, targetWorkItem, sourceWorkItem.getWorkItemType(), valueId, workItemServer, monitor);
} else if (WorkItemAttributes.RESOLUTION.equals(identifier)) {
if (WorkItemAttributes.RESOLUTION.equals(identifier)) {
ResolutionHelpers.setResolution(targetWorkItem, valueId, workItemServer, monitor);
} else if (WorkItemAttributes.STATE.equals(identifier)) {
StateHelpers.setState(targetWorkItem, valueId, workItemServer, monitor);
Expand All @@ -84,9 +84,7 @@ public AttributeValue getCurrentValueRepresentation(IAttribute attribute, IWorkI
AttributeValue value = new AttributeValue("", "");;

if(attributeValue != null) {
if (WorkItemAttributes.TYPE.equals(identifier)) {
value = WorkItemTypeHelpers.getWorkItemType(attributeValue, pa, workItemServer, monitor);
} else if (WorkItemAttributes.RESOLUTION.equals(identifier)) {
if (WorkItemAttributes.RESOLUTION.equals(identifier)) {
value = ResolutionHelpers.getResolution(attributeValue, workItem, workItemServer, monitor);
} else if (WorkItemAttributes.STATE.equals(identifier)) {
value = StateHelpers.getState(attributeValue, workItem, workItemServer, monitor);
Expand All @@ -109,9 +107,7 @@ public List<AttributeValue> getAvailableOptionsPresentations(IAttribute attribut
List<AttributeValue> values;
Identifier<IAttribute> identifier = WorkItemAttributes.getPropertyIdentifier(attribute.getIdentifier());

if (WorkItemAttributes.TYPE.equals(identifier)) {
values = WorkItemTypeHelpers.addWorkItemTypesAsValues(pa, workItemServer, monitor);
} else if (WorkItemAttributes.RESOLUTION.equals(identifier)) {
if (WorkItemAttributes.RESOLUTION.equals(identifier)) {
values = ResolutionHelpers.addResolutionsAsValues(pa, workItemServer, monitor);
} else if (WorkItemAttributes.STATE.equals(identifier)) {
values = StateHelpers.addStatesAsValues(pa, workItem, workItemServer, monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.common.model.IState;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemType;
import com.ibm.team.workitem.common.model.Identifier;
import com.ibm.team.workitem.common.workflow.ICombinedWorkflowInfos;
import com.ibm.team.workitem.common.workflow.IWorkflowInfo;
Expand All @@ -19,12 +20,13 @@ public final class StateHelpers {
public static final AttributeValue getState(Object stateObj, IWorkItem workItem,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
String stateId = (String)stateObj;
IWorkItemType type = workItemServer.findWorkItemType(workItem.getProjectArea(), workItem.getWorkItemType(), monitor);
IWorkflowInfo iwfl = workItemServer.findWorkflowInfo(workItem, monitor);
Identifier<IState>[] allWorkflowStates = iwfl.getAllStateIds();
for(Identifier<IState> state : allWorkflowStates) {
String id = state.getStringIdentifier();
if(id.equals(stateId)) {
String name = iwfl.getStateName(state);
String name = iwfl.getStateName(state) + " (" + type.getDisplayName() + ")";
return new AttributeValue(id, name);
}
}
Expand All @@ -48,6 +50,7 @@ public static final void setState(IWorkItem workItem, String stateId,
public static final List<AttributeValue> addStatesAsValues(IProjectAreaHandle pa, IWorkItem wi,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
List<AttributeValue> values = new ArrayList<AttributeValue>();
IWorkItemType type = workItemServer.findWorkItemType(pa, wi.getWorkItemType(), monitor);
IWorkflowInfo workFlowInfo = workItemServer.findCachedWorkflowInfo(wi);
if (workFlowInfo == null) {
workFlowInfo = workItemServer.findWorkflowInfo(wi, monitor);
Expand All @@ -59,7 +62,7 @@ public static final List<AttributeValue> addStatesAsValues(IProjectAreaHandle pa
while (n2 < n) {
Identifier<IState> stateId = identifiers[n2];
String id = stateId.getStringIdentifier();
String name = workFlowInfo.getStateName(stateId);
String name = workFlowInfo.getStateName(stateId) + " (" + type.getDisplayName() + ")";
values.add(new AttributeValue(id, name));
++n2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@

public final class WorkItemTypeHelpers {

public static final AttributeValue getWorkItemType(Object wiType, IProjectAreaHandle pa,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
String typeId = (String)wiType;
IWorkItemType type = workItemServer.findWorkItemType(pa, typeId, monitor);
String id = type.getIdentifier();
String displayName = type.getDisplayName();
return new AttributeValue(id, displayName);
}

public static final void setWorkItemType(IWorkItem sourceWorkItem, IWorkItem targetWorkItem, String odlWorkItemTypeId, String newWorkItemTypeId,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
IProjectAreaHandle sourcePa = sourceWorkItem.getProjectArea();
Expand All @@ -33,34 +24,7 @@ public static final void setWorkItemType(IWorkItem sourceWorkItem, IWorkItem tar
}
}

public static final List<AttributeValue> addWorkItemTypesAsValues(IProjectAreaHandle pa,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
List<AttributeValue> values = new ArrayList<AttributeValue>();
for (IWorkItemType type : getWorkItemTypes(pa, workItemServer, monitor)) {
String name = type.getDisplayName();
String id = type.getIdentifier();
values.add(new AttributeValue(id, name));
}
return values;
}

public static final boolean validateWorkItemTypes(List<IWorkItem> workItems, IProjectAreaHandle pa,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
List<String> typeIds = new ArrayList<String>();
List<IWorkItemType> types = getWorkItemTypes(pa, workItemServer, monitor);
for(IWorkItemType type : types) {
typeIds.add(type.getIdentifier());
}
for(IWorkItem item : workItems) {
String type = item.getWorkItemType();
if(!typeIds.contains(type)){
return false;
}
}
return true;
}

private static final List<IWorkItemType> getWorkItemTypes(IProjectAreaHandle pa, IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
public static final List<IWorkItemType> getWorkItemTypes(IProjectAreaHandle pa, IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
List<IWorkItemType> workItemTypes = workItemServer.findCachedWorkItemTypes(pa);
if (workItemTypes == null) {
workItemTypes = workItemServer.findWorkItemTypes(pa, monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,18 @@
public class AttributeDefinition {
private String identifier;
private String displayName;
private List<AttributeValue> allowedValues;
private List<MappingDefinition> valueMappings;

public AttributeDefinition(String id, String name) {
this.identifier = id;
this.displayName = name;
allowedValues = new ArrayList<AttributeValue>();
valueMappings = new ArrayList<MappingDefinition>();
}

public String getIdentifier() {
return identifier;
}

// public String getDisplayName() {
// return displayName;
// }

public List<AttributeValue> getAttributeValues() {
return allowedValues;
}
//
// public void addAllowedValue(AttributeValue attrVal) {
// allowedValues.add(attrVal);
// }

public void addAllowedValues(List<AttributeValue> attrVals) {
allowedValues.addAll(attrVals);
}

public List<MappingDefinition> getMappingDefinitions() {
return valueMappings;
}
Expand All @@ -57,10 +39,6 @@ public MappingDefinition getMapping(String oldValueIdentifier) {
return null;
}

// public void addValueMappings(List<MappingDefinition> mappingDefinitions) {
// valueMappings.addAll(mappingDefinitions);
// }

/**
* override equals to compare by unique attribute identifier
* @param object AttributeDefinition object to be compared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@
public class MappingDefinition {
private AttributeValue oldValue;
private List<AffectedWorkItem> affectedWorkItems;
private List<AttributeValue> allowedValues;
private String chosen;
private boolean showDetails = false;

public MappingDefinition(AttributeValue oldValue, AffectedWorkItem affectedWorkItem) {
this.oldValue = oldValue;
this.affectedWorkItems = new ArrayList<AffectedWorkItem>();
allowedValues = new ArrayList<AttributeValue>();
this.affectedWorkItems = new ArrayList<AffectedWorkItem>();
this.affectedWorkItems.add(affectedWorkItem);
this.chosen = "nothing";
}

public void addAffectedWorkItem(WorkItem wi, boolean isRequired) {

this.affectedWorkItems.add(new AffectedWorkItem(wi, isRequired));
}

public List<AttributeValue> getAttributeValues() {
return allowedValues;
}

public void addAllowedValues(List<AttributeValue> attrVals) {
allowedValues.addAll(attrVals);
}

public List<AffectedWorkItem> getAffectedWorkItems() {
return this.affectedWorkItems;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models;

public class TypeMappingEntry {
private String source;
private String target;

public String getSource() {
return source;
}

public String getTarget() {
return target;
}
}
Loading

0 comments on commit 2a8b00c

Please sign in to comment.