Optimize mindmap list query.
This commit is contained in:
@@ -59,7 +59,7 @@ public class LabelController extends BaseController {
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void deleteLabelById(@PathVariable int id) throws WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final Label label = labelService.getLabelById(id, user);
|
||||
final Label label = labelService.findLabelById(id, user);
|
||||
if (label == null) {
|
||||
throw new LabelCouldNotFoundException("Label could not be found. Id: " + id);
|
||||
}
|
||||
|
||||
@@ -71,16 +71,12 @@ public class MindmapController extends BaseController {
|
||||
final User user = Utils.getUser();
|
||||
|
||||
final MindmapFilter filter = MindmapFilter.parse(q);
|
||||
final List<Collaboration> collaborations = mindmapService.findCollaborations(user);
|
||||
logger.debug("Collaborators list: " + collaborations.size());
|
||||
List<Mindmap> mindmaps = mindmapService.findMindmapsByUser(user);
|
||||
mindmaps = mindmaps
|
||||
.stream()
|
||||
.filter(m->filter.accept(m, user))
|
||||
.collect(Collectors.toUnmodifiableList());
|
||||
|
||||
final List<Mindmap> mindmaps = new ArrayList<>();
|
||||
for (Collaboration collaboration : collaborations) {
|
||||
final Mindmap mindmap = collaboration.getMindMap();
|
||||
if (filter.accept(mindmap, user)) {
|
||||
mindmaps.add(mindmap);
|
||||
}
|
||||
}
|
||||
return new RestMindmapList(mindmaps, user);
|
||||
}
|
||||
|
||||
@@ -175,7 +171,7 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
|
||||
mindmap.setXmlStr(xmlDoc);
|
||||
saveMindmapDocument(false,mindmap,user);
|
||||
saveMindmapDocument(false, mindmap, user);
|
||||
}
|
||||
|
||||
|
||||
@@ -247,11 +243,6 @@ public class MindmapController extends BaseController {
|
||||
mindmap.setDescription(description);
|
||||
}
|
||||
|
||||
final String tags = restMindmap.getTags();
|
||||
if (tags != null) {
|
||||
mindmap.setTags(tags);
|
||||
}
|
||||
|
||||
// Update document properties ...
|
||||
final String properties = restMindmap.getProperties();
|
||||
if (properties != null) {
|
||||
@@ -350,16 +341,16 @@ public class MindmapController extends BaseController {
|
||||
|
||||
restCollabs
|
||||
.getCollaborations()
|
||||
.forEach(collab->{
|
||||
.forEach(collab -> {
|
||||
final String email = collab.getEmail();
|
||||
if(mapsByEmail.containsKey(email)){
|
||||
if (mapsByEmail.containsKey(email)) {
|
||||
try {
|
||||
mindmapService.removeCollaboration(mindMap, mapsByEmail.get(email));
|
||||
} catch (CollaborationException e) {
|
||||
logger.error(e);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Great, let's add all the collabs again ...
|
||||
@@ -450,7 +441,7 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
|
||||
final Collaboration collab = mindmap.findCollaboration(email);
|
||||
if(collab!=null) {
|
||||
if (collab != null) {
|
||||
CollaborationRole role = collab.getRole();
|
||||
|
||||
// Owner collab can not be removed ...
|
||||
@@ -471,12 +462,12 @@ public class MindmapController extends BaseController {
|
||||
|
||||
// Update map status ...
|
||||
final boolean starred = Boolean.parseBoolean(value);
|
||||
final Collaboration collaboration = mindmap.findCollaboration(user);
|
||||
if (collaboration == null) {
|
||||
final Optional<Collaboration> collaboration = mindmap.findCollaboration(user);
|
||||
if (!collaboration.isPresent()) {
|
||||
throw new WiseMappingException("No enough permissions.");
|
||||
}
|
||||
collaboration.getCollaborationProperties().setStarred(starred);
|
||||
mindmapService.updateCollaboration(user, collaboration);
|
||||
collaboration.get().getCollaborationProperties().setStarred(starred);
|
||||
mindmapService.updateCollaboration(user, collaboration.get());
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/lock", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
|
||||
@@ -509,7 +500,7 @@ public class MindmapController extends BaseController {
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createMap(@RequestBody(required = false) RestMindmap restMindmap, @NotNull HttpServletResponse response, @RequestParam(required = false) String title, @RequestParam(required = false) String description) throws IOException, WiseMappingException {
|
||||
// If a default maps has not been defined, just create one ...
|
||||
if(restMindmap==null){
|
||||
if (restMindmap == null) {
|
||||
restMindmap = new RestMindmap();
|
||||
}
|
||||
|
||||
@@ -519,7 +510,7 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
if (description != null && !description.isEmpty()) {
|
||||
restMindmap.setDescription(description);
|
||||
}else {
|
||||
} else {
|
||||
restMindmap.setDescription("");
|
||||
}
|
||||
|
||||
@@ -547,7 +538,7 @@ public class MindmapController extends BaseController {
|
||||
response.setHeader("ResourceId", Integer.toString(delegated.getId()));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"},produces = {"application/xml", "application/json","text/plain"})
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"}, produces = {"application/xml", "application/json", "text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createDuplicate(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {
|
||||
// Validate ...
|
||||
@@ -586,38 +577,33 @@ public class MindmapController extends BaseController {
|
||||
result.rejectValue(fieldName, "error.not-specified", null, message);
|
||||
return new ValidationException(result);
|
||||
}
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/labels/maps/{id}")
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}/labels/{lid)}")
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void removeLabel(@RequestBody RestLabel restLabel, @PathVariable int id) throws WiseMappingException {
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
final User currentUser = Utils.getUser();
|
||||
final Label delegated = restLabel.getDelegated();
|
||||
assert currentUser != null;
|
||||
delegated.setCreator(currentUser);
|
||||
mindmapService.removeLabel(mindmap, delegated);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/labels/maps", consumes = { "application/xml","application/json"})
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public void addLabel(@RequestBody RestLabel restLabel, @RequestParam(required = true) String ids) throws WiseMappingException {
|
||||
int labelId = restLabel.getId();
|
||||
public void removeLabelFromMap(@PathVariable int id, @RequestBody int lid) throws WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final Label delegated = restLabel.getDelegated();
|
||||
delegated.setCreator(user);
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
final Label label = labelService.findLabelById(lid, 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(",")) {
|
||||
final int mindmapId = Integer.parseInt(id);
|
||||
final Mindmap mindmap = findMindmapById(mindmapId);
|
||||
final Label label = mindmap.findLabel(labelId);
|
||||
if (label == null) {
|
||||
mindmapService.linkLabel(mindmap, delegated);
|
||||
}
|
||||
if (label == null) {
|
||||
throw new LabelCouldNotFoundException("Label could not be found. Id: " + lid);
|
||||
}
|
||||
|
||||
mindmap.removeLabel(label);
|
||||
mindmapService.updateMindmap(mindmap,false);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}/labels", consumes = {"application/xml", "application/json"})
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public void updateLabel(@PathVariable int id, @RequestBody int lid) throws WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final Label label = labelService.findLabelById(lid, user);
|
||||
if (label == null) {
|
||||
throw new LabelCouldNotFoundException("Label could not be found. Id: " + lid);
|
||||
}
|
||||
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
mindmap.addLabel(label);
|
||||
mindmapService.updateMindmap(mindmap,false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.util.TimeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -33,6 +34,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@XmlRootElement(name = "map")
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
@@ -87,14 +92,6 @@ public class RestMindmap {
|
||||
mindmap.setDescription(description);
|
||||
}
|
||||
|
||||
public String getTags() {
|
||||
return mindmap.getTags();
|
||||
}
|
||||
|
||||
public void setTags(String tags) {
|
||||
mindmap.setTags(tags);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mindmap.getTitle();
|
||||
}
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
@@ -32,8 +32,10 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@XmlRootElement(name = "mapinfo")
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
@@ -46,8 +48,15 @@ import java.util.Set;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RestMindmapInfo {
|
||||
|
||||
public static final String ROLE_NONE = "none";
|
||||
@JsonIgnore
|
||||
private final Mindmap mindmap;
|
||||
@JsonIgnore
|
||||
private Set<RestLabel> restLabels;
|
||||
|
||||
@JsonIgnore
|
||||
private int mapId = -1;
|
||||
|
||||
private final Collaborator collaborator;
|
||||
|
||||
public RestMindmapInfo() {
|
||||
@@ -60,7 +69,7 @@ public class RestMindmapInfo {
|
||||
this.collaborator = collaborator;
|
||||
}
|
||||
|
||||
public void setCreationTime(String value){
|
||||
public void setCreationTime(String value) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -77,14 +86,6 @@ public class RestMindmapInfo {
|
||||
mindmap.setDescription(description);
|
||||
}
|
||||
|
||||
public String getTags() {
|
||||
return mindmap.getTags();
|
||||
}
|
||||
|
||||
public void setTags(String tags) {
|
||||
mindmap.setTags(tags);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mindmap.getTitle();
|
||||
}
|
||||
@@ -92,27 +93,40 @@ public class RestMindmapInfo {
|
||||
public void setTitle(String title) {
|
||||
mindmap.setTitle(title);
|
||||
}
|
||||
public Set<RestLabel> getLabels() {
|
||||
final Set<RestLabel> result = new LinkedHashSet<>();
|
||||
final User me = Utils.getUser();
|
||||
for (Label label : mindmap.getLabels()) {
|
||||
if (label.getCreator().equals(me)) {
|
||||
result.add(new RestLabel(label));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Set<RestLabel> getLabels() {
|
||||
// Support test deserialization...
|
||||
Set<RestLabel> result = this.restLabels;
|
||||
if(result==null) {
|
||||
final User me = Utils.getUser();
|
||||
result = mindmap.getLabels().
|
||||
stream()
|
||||
.filter(l -> l.getCreator().equals(me))
|
||||
.map(RestLabel::new)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setLabels(Set<RestLabel> restLabels) {
|
||||
this.restLabels = restLabels;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return mindmap.getId();
|
||||
int result = this.mapId;
|
||||
if(mapId==-1) {
|
||||
result = mindmap.getId();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.mapId = id;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
final User creator = mindmap.getCreator();
|
||||
return creator!=null?creator.getFullName():null;
|
||||
return creator != null ? creator.getFullName() : null;
|
||||
}
|
||||
|
||||
public void setCreator(String email) {
|
||||
@@ -124,8 +138,8 @@ public class RestMindmapInfo {
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
final Collaboration collaboration = mindmap.findCollaboration(Utils.getUser());
|
||||
return collaboration != null ? collaboration.getRole().getLabel() : "none";
|
||||
final Optional<Collaboration> collaboration = mindmap.findCollaboration(Utils.getUser());
|
||||
return collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE);
|
||||
}
|
||||
|
||||
public void setRole(String value) {
|
||||
@@ -142,7 +156,7 @@ public class RestMindmapInfo {
|
||||
|
||||
public String getLastModificationTime() {
|
||||
final Calendar calendar = mindmap.getLastModificationTime();
|
||||
return calendar!=null?TimeUtils.toISO8601(calendar.getTime()):null;
|
||||
return calendar != null ? TimeUtils.toISO8601(calendar.getTime()) : null;
|
||||
}
|
||||
|
||||
public void setLastModificationTime(String value) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@XmlRootElement(name = "maps")
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
@@ -47,10 +48,9 @@ public class RestMindmapList {
|
||||
}
|
||||
|
||||
public RestMindmapList(@NotNull List<Mindmap> mindmaps, @NotNull Collaborator collaborator) {
|
||||
this.mindmapsInfo = new ArrayList<>(mindmaps.size());
|
||||
for (Mindmap mindMap : mindmaps) {
|
||||
this.mindmapsInfo.add(new RestMindmapInfo(mindMap, collaborator));
|
||||
}
|
||||
this.mindmapsInfo = mindmaps.stream()
|
||||
.map(m->new RestMindmapInfo(m, collaborator))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
|
||||
Reference in New Issue
Block a user