Initial commit
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.rest;
|
||||
|
||||
@@ -53,7 +53,6 @@ import com.wisemapping.service.MindmapService;
|
||||
import com.wisemapping.validator.MapInfoValidator;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiParam;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -73,6 +72,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
@@ -85,7 +85,6 @@ import java.util.Set;
|
||||
@Api(value = "mindmap", description = "User Mindmap Objects.")
|
||||
@Controller
|
||||
public class MindmapController extends BaseController {
|
||||
private final static Logger logger = Logger.getLogger("com.wisemapping");
|
||||
|
||||
private static final String LATEST_HISTORY_REVISION = "latest";
|
||||
|
||||
@@ -257,15 +256,13 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/document/xml", "/maps/{id}/document/xml-pub"}, consumes = {"text/plain"}, produces = {"application/xml"})
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/document/xml", "/maps/{id}/document/xml-pub"}, consumes = {"text/plain"}, produces = {"application/xml; charset=UTF-8"})
|
||||
@ResponseBody
|
||||
public byte[] retrieveDocument(@PathVariable int id, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
|
||||
// I should not return byte, but there is some encoding issue here. Further research needed.
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
|
||||
String xmlStr = mindmap.getXmlStr();
|
||||
return xmlStr.getBytes("UTF-8");
|
||||
return xmlStr.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@@ -284,11 +281,9 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/{hid}/document/xml"}, consumes = {"text/plain"}, produces = {"application/xml"})
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/{hid}/document/xml"}, consumes = {"text/plain"}, produces = {"application/xml; charset=UTF-8"})
|
||||
@ResponseBody
|
||||
public byte[] retrieveDocument(@PathVariable int id, @PathVariable int hid, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
|
||||
// I should not return byte, but there is some encoding issue here. Further research needed.
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
final MindMapHistory mindmapHistory = mindmapService.findMindmapHistory(id, hid);
|
||||
return mindmapHistory.getUnzipXml();
|
||||
}
|
||||
@@ -304,20 +299,16 @@ public class MindmapController extends BaseController {
|
||||
|
||||
final LockInfo lockInfo = lockManager.getLockInfo(mindmap);
|
||||
if (lockInfo.getUser().identityEquality(user)) {
|
||||
long savedTimestamp = mindmap.getLastModificationTime().getTimeInMillis();
|
||||
final boolean outdated = savedTimestamp > timestamp;
|
||||
|
||||
final boolean outdated = mindmap.getLastModificationTime().getTimeInMillis() > timestamp;
|
||||
if (lockInfo.getSession() == session) {
|
||||
// Timestamp might not be returned to the client. This try to cover this case, ignoring the client timestamp check.
|
||||
final User lastEditor = mindmap.getLastEditor();
|
||||
boolean editedBySameUser = lastEditor == null || user.identityEquality(lastEditor);
|
||||
if (outdated && !editedBySameUser) {
|
||||
throw new SessionExpiredException("Map has been updated by " + (lastEditor.getEmail()) + ",Timestamp:" + timestamp + "," + savedTimestamp + ", User:" + lastEditor.getId() + ":" + user.getId() + ",Mail:'" + lastEditor.getEmail() + "':'" + user.getEmail(), lastEditor);
|
||||
throw new SessionExpiredException("Map has been updated by " + (lastEditor.getEmail()) + ",Timestamp:" + timestamp + "," + mindmap.getLastModificationTime().getTimeInMillis() + ", User:" + lastEditor.getId() + ":" + user.getId() + ",Mail:'" + lastEditor.getEmail() + "':'" + user.getEmail(), lastEditor);
|
||||
}
|
||||
} else if (outdated) {
|
||||
logger.warn("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + savedTimestamp);
|
||||
// @Todo: Temporally disabled to unblock save action. More research needed.
|
||||
// throw new MultipleSessionsOpenException("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + savedTimestamp);
|
||||
throw new MultipleSessionsOpenException("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + lockInfo.getTimestamp() + ",User:");
|
||||
}
|
||||
} else {
|
||||
throw new SessionExpiredException("Different Users.", lockInfo.getUser());
|
||||
@@ -395,7 +386,7 @@ public class MindmapController extends BaseController {
|
||||
// Update map ...
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
mindmap.setTitle(title);
|
||||
mindmapService.updateMindmap(mindMap, !true);
|
||||
mindmapService.updateMindmap(mindMap, false);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs", consumes = {"application/json", "application/xml"}, produces = {"application/json", "application/xml"})
|
||||
@@ -464,7 +455,7 @@ public class MindmapController extends BaseController {
|
||||
// Update map ...
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
mindmap.setDescription(description);
|
||||
mindmapService.updateMindmap(mindMap, !true);
|
||||
mindmapService.updateMindmap(mindMap, false);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/publish", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
|
||||
@@ -480,7 +471,7 @@ public class MindmapController extends BaseController {
|
||||
|
||||
// Update map status ...
|
||||
mindMap.setPublic(Boolean.parseBoolean(value));
|
||||
mindmapService.updateMindmap(mindMap, !true);
|
||||
mindmapService.updateMindmap(mindMap, false);
|
||||
|
||||
}
|
||||
|
||||
@@ -530,7 +521,7 @@ public class MindmapController extends BaseController {
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void batchDelete(@RequestParam(required = true) String ids) throws IOException, WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final String[] mapsIds = ids.split(",");
|
||||
final String[] mapsIds = ",".split(ids);
|
||||
for (final String mapId : mapsIds) {
|
||||
final Mindmap mindmap = findMindmapById(Integer.parseInt(mapId));
|
||||
mindmapService.removeMindmap(mindmap, user);
|
||||
@@ -651,11 +642,12 @@ public class MindmapController extends BaseController {
|
||||
final User user = Utils.getUser();
|
||||
final Label delegated = restLabel.getDelegated();
|
||||
delegated.setCreator(user);
|
||||
|
||||
final Label found = labelService.getLabelById(labelId, user);
|
||||
if (found == null) {
|
||||
throw new LabelCouldNotFoundException("Label could not be found. Id: " + labelId);
|
||||
}
|
||||
for (String id : ids.split(",")) {
|
||||
for (String id : ",".split(ids)) {
|
||||
final int mindmapId = Integer.parseInt(id);
|
||||
final Mindmap mindmap = findMindmapById(mindmapId);
|
||||
final Label label = mindmap.findLabel(labelId);
|
||||
|
Reference in New Issue
Block a user