link label to mindmaps

This commit is contained in:
Ezequiel Bergamaschi 2014-01-28 02:28:16 -03:00 committed by Ezequiel Bergamaschi
parent 72a46367d6
commit 2ec941e1a0
10 changed files with 94 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package com.wisemapping.dao;
import com.wisemapping.model.Label; import com.wisemapping.model.Label;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -14,6 +15,10 @@ public interface LabelManager {
@NotNull @NotNull
List<Label> getAllLabels(@NotNull final User user); List<Label> getAllLabels(@NotNull final User user);
@Nullable
Label getLabelById(int id);
@Nullable @Nullable
Label getLabelByTitle(@NotNull final String title, @NotNull final User user); Label getLabelByTitle(@NotNull final String title, @NotNull final User user);
} }

View File

@ -3,6 +3,7 @@ package com.wisemapping.dao;
import com.wisemapping.model.Label; import com.wisemapping.model.Label;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import java.util.List; import java.util.List;
@ -25,6 +26,13 @@ public class LabelManagerImpl extends HibernateDaoSupport
public List<Label> getAllLabels(@NotNull final User user) { public List<Label> getAllLabels(@NotNull final User user) {
return getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where creator_id=?", user.getId()); return getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where creator_id=?", user.getId());
} }
@Nullable
@Override
public Label getLabelById(int id) {
return getHibernateTemplate().get(Label.class, id);
}
@Nullable @Nullable
@Override @Override
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) { public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
@ -35,4 +43,6 @@ public class LabelManagerImpl extends HibernateDaoSupport
} }
return result; return result;
} }
} }

View File

@ -0,0 +1,19 @@
package com.wisemapping.exceptions;
import org.jetbrains.annotations.NotNull;
public class LabelCouldNotFoundException extends ClientException {
private static final String MSG_KEY = "LABEL_CAN_NOT_BE_FOUND";
public LabelCouldNotFoundException(@NotNull String msg)
{
super(msg,Severity.FATAL);
}
@NotNull
@Override
protected String getMsgBundleKey() {
return MSG_KEY;
}
}

View File

@ -44,6 +44,7 @@ public class Mindmap {
private User lastEditor; private User lastEditor;
private Set<Collaboration> collaborations = new HashSet<Collaboration>(); private Set<Collaboration> collaborations = new HashSet<Collaboration>();
private Set<Label> labels = new HashSet<Label>();
private User creator; private User creator;
private String tags; private String tags;
@ -118,6 +119,18 @@ public class Mindmap {
collaborations.add(collaboration); collaborations.add(collaboration);
} }
@NotNull public Set<Label> getLabels() {
return labels;
}
public void setLabels(@NotNull final Set<Label> labels) {
this.labels = labels;
}
public void addLabel(@NotNull final Label label) {
this.labels.add(label);
}
@Nullable @Nullable
public Collaboration findCollaboration(@NotNull Collaborator collaborator) { public Collaboration findCollaboration(@NotNull Collaborator collaborator) {
Collaboration result = null; Collaboration result = null;

View File

@ -1,12 +1,18 @@
package com.wisemapping.rest; package com.wisemapping.rest;
import com.wisemapping.exceptions.LabelCouldNotFoundException;
import com.wisemapping.exceptions.MapCouldNotFoundException;
import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.Label; import com.wisemapping.model.Label;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import com.wisemapping.rest.model.RestLabel; import com.wisemapping.rest.model.RestLabel;
import com.wisemapping.rest.model.RestLabelList; import com.wisemapping.rest.model.RestLabelList;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.security.Utils; import com.wisemapping.security.Utils;
import com.wisemapping.service.LabelService; import com.wisemapping.service.LabelService;
import com.wisemapping.service.MindmapService;
import com.wisemapping.validator.LabelValidator; import com.wisemapping.validator.LabelValidator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +21,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -22,7 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Controller @Controller
@ -31,6 +37,9 @@ public class LabelController extends BaseController {
@Qualifier("labelService") @Qualifier("labelService")
@Autowired @Autowired
private LabelService labelService; private LabelService labelService;
@Qualifier("mindmapService")
@Autowired
private MindmapService mindmapService;
@RequestMapping(method = RequestMethod.POST, value = "/labels", consumes = {"application/json"}) @RequestMapping(method = RequestMethod.POST, value = "/labels", consumes = {"application/json"})
@ -45,7 +54,7 @@ public class LabelController extends BaseController {
// Validate ... // Validate ...
final BindingResult result = new BeanPropertyBindingResult(restLabel, ""); final BindingResult result = new BeanPropertyBindingResult(restLabel, "");
new LabelValidator().validate(label, result); new LabelValidator(labelService).validate(label, result);
if (result.hasErrors()) { if (result.hasErrors()) {
throw new ValidationException(result); throw new ValidationException(result);
} }
@ -67,4 +76,20 @@ public class LabelController extends BaseController {
return new RestLabelList(all); return new RestLabelList(all);
} }
@RequestMapping(method = RequestMethod.PUT, value = "/labels/{id}/maps", consumes = {"text/plain"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void linkToMindMaps(@PathVariable int id, @RequestBody String ids) throws WiseMappingException {
final Label label = labelService.getLabelById(id);
if (label == null) {
throw new LabelCouldNotFoundException("Label could not be found. Id: " + id);
}
for (String mindmapId : ids.split(",")) {
final Mindmap mindmap = mindmapService.findMindmapById(Integer.parseInt(mindmapId));
if (mindmap == null) {
throw new MapCouldNotFoundException("Map could not be found. Id:" + id);
}
mindmap.addLabel(label);
mindmapService.updateMindmap(mindmap, false);
}
}
} }

View File

@ -48,7 +48,7 @@ public class RestMindmapList {
} }
public RestMindmapList(@NotNull List<Mindmap> mindmaps, @NotNull Collaborator collaborator) { public RestMindmapList(@NotNull List<Mindmap> mindmaps, @NotNull Collaborator collaborator) {
this.mindmapsInfo = new ArrayList<RestMindmapInfo>(); this.mindmapsInfo = new ArrayList<>(mindmaps.size());
for (Mindmap mindMap : mindmaps) { for (Mindmap mindMap : mindmaps) {
this.mindmapsInfo.add(new RestMindmapInfo(mindMap, collaborator)); this.mindmapsInfo.add(new RestMindmapInfo(mindMap, collaborator));
} }

View File

@ -4,6 +4,7 @@ import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.Label; import com.wisemapping.model.Label;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -12,5 +13,9 @@ public interface LabelService {
void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException; void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException;
@NotNull List<Label> getAll(@NotNull final User user); @NotNull List<Label> getAll(@NotNull final User user);
@Nullable
Label getLabelById(int id);
public Label getLabelByTitle(@NotNull String title, @NotNull final User user); public Label getLabelByTitle(@NotNull String title, @NotNull final User user);
} }

View File

@ -5,6 +5,7 @@ import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.Label; import com.wisemapping.model.Label;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -29,6 +30,11 @@ public class LabelServiceImpl implements LabelService {
return labelManager.getAllLabels(user); return labelManager.getAllLabels(user);
} }
@Override @Nullable
public Label getLabelById(int id) {
return labelManager.getLabelById(id);
}
@Nullable @Nullable
@Override @Override
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) { public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {

View File

@ -25,6 +25,13 @@
<key column="mindmap_id" not-null="true"/> <key column="mindmap_id" not-null="true"/>
<one-to-many class="com.wisemapping.model.Collaboration"/> <one-to-many class="com.wisemapping.model.Collaboration"/>
</set> </set>
<set name = "labels"
table="R_LABEL_MINDMAP"
cascade="all,delete-orphan,save-update">
<key column="mindmap_id" not-null="true"/>
<many-to-many column="label_id" class="com.wisemapping.model.Label"/>
</set>
</class> </class>
</hibernate-mapping> </hibernate-mapping>

View File

@ -252,6 +252,7 @@ CONTACT_US=Contact Us
CAPTCHA_LOADING_ERROR=ReCaptcha could not be loaded. You must have access to Google ReCaptcha service. CAPTCHA_LOADING_ERROR=ReCaptcha could not be loaded. You must have access to Google ReCaptcha service.
ACCESS_HAS_BEEN_REVOKED= Upps. your access permissions to this map has been revoked. Contact map owner. ACCESS_HAS_BEEN_REVOKED= Upps. your access permissions to this map has been revoked. Contact map owner.
MAP_CAN_NOT_BE_FOUND= Upps. The map can not be found. It must have been deleted. MAP_CAN_NOT_BE_FOUND= Upps. The map can not be found. It must have been deleted.
LABEL_CAN_NOT_BE_FOUND= Upps. The label can not be found. It must have been deleted.
LICENSE=License LICENSE=License
WELCOME_TO_WISEMAPPING=Welcome to WiseMapping WELCOME_TO_WISEMAPPING=Welcome to WiseMapping
WELCOME_DETAILS=WiseMapping will enable you to create and read your mind maps everywhere. With WiseMapping you can: <ul><li>Embed mind map it in web pages and blogs</li><li>Link mind map and documents</li><li>Share your maps with friend and colleagues</li><li>Export your maps SVG,PNG,JPG and FreeMind</li></ul>. WELCOME_DETAILS=WiseMapping will enable you to create and read your mind maps everywhere. With WiseMapping you can: <ul><li>Embed mind map it in web pages and blogs</li><li>Link mind map and documents</li><li>Share your maps with friend and colleagues</li><li>Export your maps SVG,PNG,JPG and FreeMind</li></ul>.