Skip to content

Commit

Permalink
add Unset Rank feature, upgrade dependencies - v1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Steiger committed Jul 3, 2019
1 parent 7a8e0ed commit 6c89174
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 84 deletions.
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.5.0.qualifier"
version="1.5.2.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.5.0-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
6 changes: 3 additions & 3 deletions 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.5.0.qualifier
Bundle-Version: 1.5.2.qualifier
Bundle-Vendor: VENDOR
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle:
Expand Down Expand Up @@ -31,8 +31,8 @@ Require-Bundle:
com.ibm.team.jfs.app.error,
com.ibm.team.process.common,
com.ibm.team.process.service
Bundle-ClassPath: target/dependency/gson-2.7.jar,
target/dependency/com.siemens.bt.jazz.services.base-2.0.1-SNAPSHOT.jar,
Bundle-ClassPath: target/dependency/gson-2.8.5.jar,
target/dependency/com.siemens.bt.jazz.services.base-3.0.3-SNAPSHOT.jar,
.
Import-Package: com.ibm.team.jfs.app,
com.ibm.team.jfs.app.http.util,
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.5.0-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.siemens.bt.jazz.services.WorkItemBulkMover;

import com.ibm.team.jfs.app.http.util.HttpConstants.HttpMethod;
import com.siemens.bt.jazz.services.WorkItemBulkMover.services.InfoService;
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;

public class WorkItemBulkMoverService extends BaseService implements IWorkItemBulkMoverService {
public WorkItemBulkMoverService() {
super();
router.addService(HttpMethod.POST, "info", new RestFactory(InfoService.class));
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));
router.get("info", InfoService.class);
router.post("move", MoveService.class);
router.get("project-areas", ProjectAreaService.class);
router.get("types", ProjectAreaTypeService.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.ibm.team.workitem.service.internal.WorkItemWrapper;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.helpers.AttributeHelpers;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.helpers.CategoryHelpers;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.helpers.RankHelpers;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.helpers.WorkItemTypeHelpers;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models.*;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.operations.BulkMoveOperation;
Expand Down Expand Up @@ -47,12 +48,12 @@ public WorkItemMover(TeamRawService parentService) {
* @throws TeamRepositoryException if anything with RTC goes wrong
*/
@SuppressWarnings("restriction")
public MovePreparationResult PrepareMove(List<IWorkItem> sourceWorkItems, IProjectAreaHandle targetArea, List<AttributeDefinition> mappingDefinitions, Map<String, String> typeMap) throws TeamRepositoryException {
public MovePreparationResult PrepareMove(List<IWorkItem> sourceWorkItems, IProjectAreaHandle targetArea, List<AttributeDefinition> mappingDefinitions, Map<String, String> typeMap, boolean removeRank) throws TeamRepositoryException {
// run the bulk movement operation
BulkMoveOperation oper = new BulkMoveOperation(targetArea, service);
oper.run(sourceWorkItems, workItemServer, monitor);

// get the workitems involved into the move operation
// get the work items involved into the move operation
List<WorkItemMoveMapper> workItems = oper.getMappedWorkItems();
if(workItems.size() < sourceWorkItems.size()) {
List<Integer> mappedIds = new ArrayList<Integer>();
Expand All @@ -79,6 +80,10 @@ public MovePreparationResult PrepareMove(List<IWorkItem> sourceWorkItems, IProje
}

WorkItemTypeHelpers.setWorkItemType(entry.getSourceWorkItem(), entry.getTargetWorkItem(), sourceType, targetType, workItemServer, monitor);

if(removeRank) {
RankHelpers.unsetRank(entry.getTargetWorkItem(), workItemServer);
}
}

if(mappingDefinitions != null && mappingDefinitions.size() > 0) {
Expand Down Expand Up @@ -277,8 +282,8 @@ private boolean isTargetRequiredButValueUnassigned(boolean isRequired, IAttribut
return isRequired && AttributeTypes.CATEGORY.equals(attribute.getAttributeType()) && CategoryHelpers.isArchivedOrUnassigned(targetValue, service);
}

private boolean areBothNullButRequired(boolean isReuqired, Object sourceValue, Object targetValue) {
return sourceValue == null && targetValue == null && isReuqired;
private boolean areBothNullButRequired(boolean isRequired, Object sourceValue, Object targetValue) {
return sourceValue == null && targetValue == null && isRequired;
}

private boolean areValuesEqual(Object sourceValue, Object targetValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,25 @@ public AttributeValue getCurrentValueRepresentation(IAttribute attribute, IWorkI
JsonPrimitive nullPrim = null;
AttributeValue value = new AttributeValue(attribute.getIdentifier(), nullPrim);

if(attribute != null) {
String type = attribute.getAttributeType();
Object attributeValue = attribute.getValue(auditSrv, workItem, monitor);
Identifier<IAttribute> identifier = WorkItemAttributes.getPropertyIdentifier(attribute.getIdentifier());
String type = attribute.getAttributeType();
Object attributeValue = attribute.getValue(auditSrv, workItem, monitor);
Identifier<IAttribute> identifier = WorkItemAttributes.getPropertyIdentifier(attribute.getIdentifier());

if (attributeValue != null) {
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);
} else if (AttributeTypes.CATEGORY.equals(type)) {
value = CategoryHelpers.getCategory(attributeValue, workItemServer, teamRawService, monitor);
} else if (AttributeTypes.ITERATION.equals(type)) {
value = TargetHelpers.getTarget(attributeValue, auditSrv, teamRawService, monitor);
} else if (AttributeTypes.DELIVERABLE.equals(type)) {
value = FoundInHelpers.getFoundIn(attributeValue, teamRawService);
} else if (EnumerationHelpers.isValidEnumerationLiteral(attribute)) {
value = EnumerationHelpers.getEnumerationLiteral(attribute, attributeValue, workItemServer, monitor);
} else if (isPrimitiveCustomAttributeType(attribute)) {
value = PrimitiveHelpers.getPrimitive(workItem, attribute);
}
if (attributeValue != null) {
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);
} else if (AttributeTypes.CATEGORY.equals(type)) {
value = CategoryHelpers.getCategory(attributeValue, workItemServer, teamRawService, monitor);
} else if (AttributeTypes.ITERATION.equals(type)) {
value = TargetHelpers.getTarget(attributeValue, auditSrv, teamRawService, monitor);
} else if (AttributeTypes.DELIVERABLE.equals(type)) {
value = FoundInHelpers.getFoundIn(attributeValue, teamRawService);
} else if (EnumerationHelpers.isValidEnumerationLiteral(attribute)) {
value = EnumerationHelpers.getEnumerationLiteral(attribute, attributeValue, workItemServer, monitor);
} else if (isPrimitiveCustomAttributeType(attribute)) {
value = PrimitiveHelpers.getPrimitive(workItem, attribute);
}
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static boolean isValidEnumerationLiteral(IAttribute attribute) {

static AttributeValue getEnumerationLiteral(IAttribute attribute, Object t_val,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
//noinspection unchecked
Identifier<? extends ILiteral> lit = (Identifier<? extends ILiteral>)t_val;
IEnumeration<? extends ILiteral> enumeration = workItemServer.resolveEnumeration(attribute, monitor);
List<? extends ILiteral> list = enumeration.getEnumerationLiterals(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

import java.sql.Timestamp;

public final class PrimitiveHelpers {
final class PrimitiveHelpers {

public static AttributeValue getPrimitive(IWorkItem workItem, IAttribute attribute) {
static AttributeValue getPrimitive(IWorkItem workItem, IAttribute attribute) {
Object val = workItem.getValue(attribute);
JsonPrimitive primitivo;
if(val == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.helpers;

import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.common.model.IAttribute;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.service.IWorkItemServer;

public final class RankHelpers {
private static final String RANK_ATTR_ID = "com.ibm.team.apt.attribute.planitem.newRanking._pm7NmRYUEd6L1tNIGdz5qQ";

public static void unsetRank(IWorkItem wi, IWorkItemServer wiSrv) throws TeamRepositoryException {
IAttribute attr = wiSrv.findAttribute(wi.getProjectArea(), RANK_ATTR_ID, null);
if(wi.hasAttribute(attr)) {
Object existing = wi.getValue(attr);
wi.removeCustomAttribute(attr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static void setState(IWorkItem workItem, String stateId,
for(Identifier<IState> state : allWorkflowStates) {
String id = state.getStringIdentifier();
if(id.equals(stateId)) {
//noinspection deprecation
workItem.setState2(state);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
package com.siemens.bt.jazz.services.WorkItemBulkMover.services;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ibm.team.process.common.IProjectAreaHandle;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.TeamRawService;
import com.ibm.team.workitem.common.model.IWorkItemType;
import com.ibm.team.workitem.service.IWorkItemServer;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.helpers.WorkItemTypeHelpers;
import com.siemens.bt.jazz.services.WorkItemBulkMover.helpers.ProjectAreaHelpers;
import com.siemens.bt.jazz.services.base.rest.AbstractRestService;
import com.siemens.bt.jazz.services.base.rest.RestRequest;
import com.siemens.bt.jazz.services.base.rest.parameters.PathParameters;
import com.siemens.bt.jazz.services.base.rest.parameters.RestRequest;
import com.siemens.bt.jazz.services.base.rest.service.AbstractRestService;
import org.apache.commons.logging.Log;
import org.apache.http.auth.AuthenticationException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Version;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class InfoService extends AbstractRestService {
public InfoService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService) {
super(log, request, response, restRequest, parentService);
public InfoService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService, PathParameters pathParameters) {
super(log, request, response, restRequest, parentService, pathParameters);
}

public void execute() throws IOException, URISyntaxException, AuthenticationException {
public void execute() throws IOException {
Version v = Platform.getBundle("com.siemens.bt.jazz.services.WorkItemBulkMover").getVersion();
JsonObject statusObject = new JsonObject();
statusObject.addProperty("version", v.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models.TypeMappingEntry;
import com.siemens.bt.jazz.services.WorkItemBulkMover.helpers.ProjectAreaHelpers;
import com.siemens.bt.jazz.services.WorkItemBulkMover.helpers.WorkItemHelpers;
import com.siemens.bt.jazz.services.base.rest.AbstractRestService;
import com.siemens.bt.jazz.services.base.rest.RestRequest;
import com.siemens.bt.jazz.services.base.rest.parameters.PathParameters;
import com.siemens.bt.jazz.services.base.rest.parameters.RestRequest;
import com.siemens.bt.jazz.services.base.rest.service.AbstractRestService;
import com.siemens.bt.jazz.services.base.utils.RequestReader;
import org.apache.commons.logging.Log;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -36,8 +37,9 @@ public class MoveService extends AbstractRestService {
private Type typeMappingCollectionType;
private Type resultsType;

public MoveService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService) {
super(log, request, response, restRequest, parentService);
public MoveService(Log log, HttpServletRequest request, HttpServletResponse response,
RestRequest restRequest, TeamRawService parentService, PathParameters pathParameters) {
super(log, request, response, restRequest, parentService, pathParameters);
this.workItemServer = parentService.getService(IWorkItemServer.class);
this.monitor = new NullProgressMonitor();
this.gson = new GsonBuilder().serializeNulls().create();
Expand All @@ -52,14 +54,16 @@ public void execute() throws IOException {
WorkItemMover mover = new WorkItemMover(parentService);
boolean isMoved = false;
boolean previewOnly = false;
boolean skipEmail = false;
boolean skipEmail = false; // 'false' to ensure backward compatibility
boolean removeRank = false; // 'false' to ensure backward compatibility
String error = null;
Collection<AttributeDefinition> moveResults = null;

// read request data
JsonObject workItemData = RequestReader.readAsJson(request);
JsonPrimitive previewPrimitive = workItemData.getAsJsonPrimitive("previewOnly");
JsonPrimitive skipEmailPrimitive = workItemData.getAsJsonPrimitive("skipEmail");
JsonPrimitive removeRankPrimitive = workItemData.getAsJsonPrimitive("removeRank");
JsonPrimitive targetPA = workItemData.getAsJsonPrimitive("targetProjectArea");
JsonArray workItemJson = workItemData.getAsJsonArray("workItems");
JsonArray typeMappingJson = workItemData.getAsJsonArray("typeMapping");
Expand All @@ -71,6 +75,9 @@ public void execute() throws IOException {
if(skipEmailPrimitive != null) {
skipEmail = skipEmailPrimitive.getAsBoolean();
}
if(removeRankPrimitive != null) {
removeRank = removeRankPrimitive.getAsBoolean();
}
// map client data to model
Collection<Integer> clientWorkItemList = gson.fromJson(workItemJson, workItemIdCollectionType);
List<AttributeDefinition> clientMappingDefinitions = gson.fromJson(attributesJson, attributesCollectionType);
Expand All @@ -88,7 +95,7 @@ public void execute() throws IOException {
IProjectAreaHandle targetArea = ProjectAreaHelpers.getProjectArea(targetPA.getAsString(), parentService);

// prepare movement and track fields to be changed
MovePreparationResult preparationResult = mover.PrepareMove(items, targetArea, clientMappingDefinitions, typeMap);
MovePreparationResult preparationResult = mover.PrepareMove(items, targetArea, clientMappingDefinitions, typeMap, removeRank);

// store attribute based observations to be able to return this information to the end user
moveResults = preparationResult.getAttributeDefinitions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@
import com.ibm.team.repository.service.IRepositoryItemService;
import com.ibm.team.repository.service.TeamRawService;
import com.siemens.bt.jazz.services.WorkItemBulkMover.rtc.models.ProjectArea;
import com.siemens.bt.jazz.services.base.rest.AbstractRestService;
import com.siemens.bt.jazz.services.base.rest.RestRequest;
import com.siemens.bt.jazz.services.base.rest.parameters.PathParameters;
import com.siemens.bt.jazz.services.base.rest.parameters.RestRequest;
import com.siemens.bt.jazz.services.base.rest.service.AbstractRestService;
import org.apache.commons.logging.Log;
import org.apache.http.auth.AuthenticationException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.*;

public class ProjectAreaService extends AbstractRestService {

public ProjectAreaService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService) {
super(log, request, response, restRequest, parentService);
public ProjectAreaService(Log log, HttpServletRequest request, HttpServletResponse response,
RestRequest restRequest, TeamRawService parentService, PathParameters pathParameters) {
super(log, request, response, restRequest, parentService, pathParameters);
}

public void execute() throws IOException, URISyntaxException, AuthenticationException {
public void execute() {
Gson googleJson = new Gson();
String ignoredProjectAreas = restRequest.getParameterValue("ignore");
List<String> ignorePrjAreaList;
Expand Down
Loading

0 comments on commit 6c89174

Please sign in to comment.