Skip to content

Commit 6051531

Browse files
committed
modified share history endpoint, so it returns a status message
1 parent aa33a20 commit 6051531

1 file changed

Lines changed: 5 additions & 21 deletions

File tree

src/main/java/de/unirostock/sems/cbarchive/web/rest/ShareApi.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.net.URI;
2525
import java.net.URISyntaxException;
2626
import java.nio.file.Files;
27+
import java.text.MessageFormat;
2728
import java.text.ParseException;
2829
import java.util.ArrayList;
2930
import java.util.Date;
@@ -188,6 +189,7 @@ public Response setWorkspaceHistory( @CookieParam(Fields.COOKIE_PATH) String old
188189
}
189190

190191
WorkspaceHistory history = null;
192+
int migration_count = 0;
191193
try {
192194
if( historyCookie != null && !historyCookie.isEmpty() ) {
193195
history = WorkspaceHistory.fromCookieJson(historyCookie);
@@ -208,6 +210,7 @@ public Response setWorkspaceHistory( @CookieParam(Fields.COOKIE_PATH) String old
208210
if( history.containsWorkspace(workspace.getWorkspaceId()) == false ) {
209211
history.getRecentWorkspaces().add( workspace );
210212
LOGGER.debug("Added shared workspace ", workspace.getWorkspaceId(), " to history. Wasn't added yet.");
213+
migration_count++;
211214
}
212215
}
213216
}
@@ -231,29 +234,10 @@ public Response setWorkspaceHistory( @CookieParam(Fields.COOKIE_PATH) String old
231234
return buildErrorResponse(500, user, "Error parsing workspace history cookie ", historyCookie, e.getMessage());
232235
}
233236

234-
String result = "setted " + user.getWorkspaceId();
235-
URI newLocation = null;
236-
try {
237-
if( requestContext != null ) {
238-
String uri = requestContext.getRequestURL().toString();
239-
// String uri = requestContext.getRequestURI();
240-
uri = uri.substring(0, uri.indexOf("rest/"));
241-
LOGGER.info("redirect sharing link ", requestContext.getRequestURL(), " to ", uri);
242-
newLocation = new URI( uri );
243-
// newLocation = new URI(requestContext.getScheme(), null, requestContext.getServerName(),
244-
// requestContext.getServerPort(), uri, requestContext.getQueryString(), null);
245-
}
246-
else
247-
newLocation = new URI("../");
248-
249-
} catch (URISyntaxException e) {
250-
LOGGER.error(e, "Cannot generate relative URL to main app");
251-
return null;
252-
}
253-
237+
String result = MessageFormat.format("{0,choice,0#Failed,|0<Successfully} migrated {0,choice,0#no workspace|1#one workspace|1<{0,number,integer} workspaces}." , migration_count);
254238
return buildResponse(302, user)
255239
.cookie( new NewCookie(Fields.COOKIE_WORKSPACE_HISTORY, historyCookie, "/", null, null, Fields.COOKIE_AGE, false) )
256-
.entity(result).location(newLocation).build();
240+
.entity(result).build();
257241
}
258242

259243
@GET

0 commit comments

Comments
 (0)