Skip to content

Commit

Permalink
switch to excplicit UTF-8 usage - introduces support for other langua…
Browse files Browse the repository at this point in the history
…ge, like japanese (fixes #13)
  • Loading branch information
Lukas Steiger committed Jul 16, 2019
1 parent 6c89174 commit 5ec85c7
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 57 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.2.qualifier"
version="1.5.3.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.2-SNAPSHOT</version>
<version>1.5.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 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.2.qualifier
Bundle-Version: 1.5.3.qualifier
Bundle-Vendor: VENDOR
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle:
Expand Down Expand Up @@ -32,7 +32,7 @@ Require-Bundle:
com.ibm.team.process.common,
com.ibm.team.process.service
Bundle-ClassPath: target/dependency/gson-2.8.5.jar,
target/dependency/com.siemens.bt.jazz.services.base-3.0.3-SNAPSHOT.jar,
target/dependency/com.siemens.bt.jazz.services.base-4.0.0-SNAPSHOT.jar,
.
Import-Package: com.ibm.team.jfs.app,
com.ibm.team.jfs.app.http.util,
Expand Down
19 changes: 17 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
<artifactId>com.siemens.bt.jazz.services.WorkItemBulkMover</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<parent>
<groupId>com.siemens.bt.jazz.services.WorkItemBulkMover</groupId>
<artifactId>com.siemens.bt.jazz.services.WorkItemBulkMover.parent</artifactId>
<version>1.5.2-SNAPSHOT</version>
<version>1.5.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<build>
<resources>
<resource>
<directory>${basedir}</directory>
<filtering>true</filtering>
<includes>
<include>plugin.xml</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@
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.configuration.Configuration;
import com.siemens.bt.jazz.services.base.configuration.preset.ContentConfigurator;
import com.siemens.bt.jazz.services.base.configuration.preset.EncodingConfigurator;
import org.apache.http.entity.ContentType;

import java.nio.charset.StandardCharsets;

public class WorkItemBulkMoverService extends BaseService implements IWorkItemBulkMoverService {
public WorkItemBulkMoverService() {
super();
router.get("info", InfoService.class);
router.post("move", MoveService.class);
router.get("project-areas", ProjectAreaService.class);
router.get("types", ProjectAreaTypeService.class);

// create an encoding configurator that sets utf 8 encoding for all responses
EncodingConfigurator utf = new EncodingConfigurator(StandardCharsets.UTF_8.name());
// create a content configurator that sets the response type to application/xml
ContentConfigurator xml = new ContentConfigurator(ContentType.APPLICATION_JSON.toString());
// wrap the configurators in a configuration
Configuration response = new Configuration(utf, xml);

router.get("info", InfoService.class, response);
router.post("move", MoveService.class, response);
router.get("project-areas", ProjectAreaService.class, response);
router.get("types", ProjectAreaTypeService.class, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.IRepositoryItemService;
import com.ibm.team.repository.service.TeamRawService;
import com.ibm.team.workitem.common.model.*;
import com.ibm.team.workitem.common.model.IAttribute;
import com.ibm.team.workitem.common.model.IDeliverable;
import com.ibm.team.workitem.common.model.IDeliverableHandle;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.service.IWorkItemServer;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models.AttributeValue;
import org.eclipse.core.runtime.IProgressMonitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public final class RankHelpers {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.siemens.bt.jazz.services.WorkItemBulkMover.rtc.models.WorkItem;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models;

import com.ibm.team.workitem.common.model.IWorkItem;

import java.util.Collection;
import java.util.List;

import com.ibm.team.workitem.common.model.IWorkItem;

/**
* wrapper class holding all neccessary data for move service to return back to the caller
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.operations;

import java.util.ArrayList;
import java.util.List;

import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models.WorkItemMoveMapper;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.links.common.IItemReference;
import com.ibm.team.links.common.ILink;
import com.ibm.team.links.common.ILinkQueryPage;
Expand All @@ -21,16 +14,16 @@
import com.ibm.team.workitem.common.internal.model.Attachment;
import com.ibm.team.workitem.common.internal.util.EMFHelper;
import com.ibm.team.workitem.common.internal.util.PermissionContext;
import com.ibm.team.workitem.common.model.IAttachment;
import com.ibm.team.workitem.common.model.IAttachmentHandle;
import com.ibm.team.workitem.common.model.ITimeSheetEntry;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemReferences;
import com.ibm.team.workitem.common.model.IWorkItemType;
import com.ibm.team.workitem.common.model.WorkItemEndPoints;
import com.ibm.team.workitem.common.model.*;
import com.ibm.team.workitem.service.IWorkItemServer;
import com.siemens.bt.jazz.services.WorkItemBulkMover.bulkMover.models.WorkItemMoveMapper;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.EObject;

import java.util.ArrayList;
import java.util.List;

/**
* The Core Operation responsible for moving work items from one project area to another
* extends the 'CopyToProjectOperation' offered by IBM out of the box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ibm.team.repository.service.TeamRawService;
import com.siemens.bt.jazz.services.base.configuration.Configuration;
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.eclipse.core.runtime.Platform;
Expand All @@ -15,8 +15,9 @@
import java.io.IOException;

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

public InfoService(String uri, Log log, HttpServletRequest request, HttpServletResponse response, Configuration configuration, TeamRawService parentService, PathParameters pathParameters) {
super(uri, log, request, response, configuration, parentService, pathParameters);
}

public void execute() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
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.internal.IAdditionalSaveParameters;
import com.ibm.team.workitem.common.model.IWorkItem;
Expand All @@ -13,8 +14,8 @@
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.configuration.Configuration;
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;
Expand All @@ -24,7 +25,9 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.*;

Expand All @@ -37,9 +40,8 @@ public class MoveService extends AbstractRestService {
private Type typeMappingCollectionType;
private Type resultsType;

public MoveService(Log log, HttpServletRequest request, HttpServletResponse response,
RestRequest restRequest, TeamRawService parentService, PathParameters pathParameters) {
super(log, request, response, restRequest, parentService, pathParameters);
public MoveService(String uri, Log log, HttpServletRequest request, HttpServletResponse response, Configuration configuration, TeamRawService parentService, PathParameters pathParameters) {
super(uri, log, request, response, configuration, parentService, pathParameters);
this.workItemServer = parentService.getService(IWorkItemServer.class);
this.monitor = new NullProgressMonitor();
this.gson = new GsonBuilder().serializeNulls().create();
Expand All @@ -60,7 +62,8 @@ public void execute() throws IOException {
Collection<AttributeDefinition> moveResults = null;

// read request data
JsonObject workItemData = RequestReader.readAsJson(request);
JsonObject workItemData = RequestReader.readAsJson(request, "UTF-8");

JsonPrimitive previewPrimitive = workItemData.getAsJsonPrimitive("previewOnly");
JsonPrimitive skipEmailPrimitive = workItemData.getAsJsonPrimitive("skipEmail");
JsonPrimitive removeRankPrimitive = workItemData.getAsJsonPrimitive("removeRank");
Expand Down Expand Up @@ -94,6 +97,10 @@ public void execute() throws IOException {
// resolve project area
IProjectAreaHandle targetArea = ProjectAreaHelpers.getProjectArea(targetPA.getAsString(), parentService);

if(targetArea == null) {
throw new TeamRepositoryException("The target project area provided by the client plugin cannot be found on the server!");
}

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

Expand All @@ -118,17 +125,14 @@ public void execute() throws IOException {
}
} catch (Exception e) {
// Inform the user the the items could not be moved
error = e.getMessage();
if(error == null) {
error = e.toString();
}
error = e.toString();
}

if(error != null) {
responseJson.addProperty("error", error);
}

// prepare data to be returend
// prepare data to be returned
responseJson.addProperty("successful", isMoved);
responseJson.add("mapping", gson.toJsonTree(moveResults, resultsType));
response.getWriter().write(gson.toJson(responseJson));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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.configuration.Configuration;
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;

Expand All @@ -20,14 +20,13 @@

public class ProjectAreaService extends AbstractRestService {

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

public void execute() {
Gson googleJson = new Gson();
String ignoredProjectAreas = restRequest.getParameterValue("ignore");
String ignoredProjectAreas = request.getParameter("ignore");
List<String> ignorePrjAreaList;
if(ignoredProjectAreas != null && ignoredProjectAreas.length() > 0) {
ignorePrjAreaList = Arrays.asList(ignoredProjectAreas.split(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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.configuration.Configuration;
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.eclipse.core.runtime.NullProgressMonitor;
Expand All @@ -25,13 +25,13 @@
import java.util.TreeMap;

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

public ProjectAreaTypeService(String uri, Log log, HttpServletRequest request, HttpServletResponse response, Configuration configuration, TeamRawService parentService, PathParameters pathParameters) {
super(uri, log, request, response, configuration, parentService, pathParameters);
}

public void execute() throws IOException, URISyntaxException {
String pa = restRequest.getParameterValue("project-area");
String pa = request.getParameter("project-area");
Map<String, JsonElement> typeMap = new TreeMap<String, JsonElement>();
try {
IProjectAreaHandle targetArea = ProjectAreaHelpers.getProjectArea(pa, parentService);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.siemens.bt.jazz.services.WorkItemBulkMover</groupId>
<artifactId>com.siemens.bt.jazz.services.WorkItemBulkMover.parent</artifactId>
<version>1.5.2-SNAPSHOT</version>
<version>1.5.3-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>com.siemens.bt.jazz.services.base</groupId>
<artifactId>com.siemens.bt.jazz.services.base</artifactId>
<version>3.0.3-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
2 changes: 1 addition & 1 deletion test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.siemens.bt.jazz.services.WorkItemBulkMover</groupId>
<artifactId>com.siemens.bt.jazz.services.WorkItemBulkMover.parent</artifactId>
<version>1.5.2-SNAPSHOT</version>
<version>1.5.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class WorkItemBulkMoverServiceTest {

Expand Down
2 changes: 1 addition & 1 deletion update-site/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.2-SNAPSHOT</version>
<version>1.5.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down

0 comments on commit 5ec85c7

Please sign in to comment.