api for unlink mindmaps
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.LabelMindmap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface LabelMindmapManager {
|
||||
|
||||
@Nullable
|
||||
LabelMindmap getLabelMindmap(final int labelId, final int mindmapId);
|
||||
|
||||
void removeLabelMindmap(@NotNull LabelMindmap labelMindmap);
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.LabelMindmap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class LabelMindmapManagerImpl extends HibernateDaoSupport
|
||||
implements LabelMindmapManager {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public LabelMindmap getLabelMindmap(int labelId, int mindmapId) {
|
||||
LabelMindmap result = null;
|
||||
List<LabelMindmap> list = getHibernateTemplate().find("from com.wisemapping.model.LabelMindmap wisemapping where mindmap_id=? and label_id=? ", new Object[]{mindmapId, labelId});
|
||||
assert list.size() <= 1;
|
||||
if (list != null && !list.isEmpty()) {
|
||||
result = list.get(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLabelMindmap(@NotNull LabelMindmap labelMindmap) {
|
||||
getHibernateTemplate().delete(labelMindmap);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.wisemapping.exceptions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LabelMindmapRelationshipNotFoundException extends ClientException {
|
||||
|
||||
private static final String MSG_KEY = "LABEL_MINDMAP_RELATION_NOT_BE_FOUND";
|
||||
|
||||
public LabelMindmapRelationshipNotFoundException(@NotNull String msg)
|
||||
{
|
||||
super(msg,Severity.WARNING);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getMsgBundleKey() {
|
||||
return MSG_KEY;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package com.wisemapping.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class LabelMindmap implements Serializable{
|
||||
|
||||
private int mindmapId;
|
||||
private int labelId;
|
||||
|
||||
public int getMindmapId() {
|
||||
return mindmapId;
|
||||
}
|
||||
|
||||
public void setMindmapId(int mindmapId) {
|
||||
this.mindmapId = mindmapId;
|
||||
}
|
||||
|
||||
public int getLabelId() {
|
||||
return labelId;
|
||||
}
|
||||
|
||||
public void setLabelId(int labelId) {
|
||||
this.labelId = labelId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof LabelMindmap)) return false;
|
||||
|
||||
LabelMindmap that = (LabelMindmap) o;
|
||||
|
||||
return labelId == that.labelId && mindmapId == that.mindmapId;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = mindmapId;
|
||||
result = 31 * result + labelId;
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.wisemapping.rest;
|
||||
|
||||
|
||||
import com.wisemapping.exceptions.LabelCouldNotFoundException;
|
||||
import com.wisemapping.exceptions.LabelMindmapRelationshipNotFoundException;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.LabelMindmap;
|
||||
import com.wisemapping.rest.model.RestLabelMindmap;
|
||||
import com.wisemapping.service.LabelMindmapService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@Controller
|
||||
public class LabelMindmapController extends BaseController {
|
||||
|
||||
@Qualifier("labelMindmapService")
|
||||
@Autowired
|
||||
private LabelMindmapService labelMindmapService;
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/labels/maps")
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void removeLabelFromMindmap(@RequestBody RestLabelMindmap restLabelMindmap) throws WiseMappingException {
|
||||
final int labelId = restLabelMindmap.getLabelId();
|
||||
final int mindmapId = restLabelMindmap.getMindmapId();
|
||||
final LabelMindmap relationship = labelMindmapService.getLabelMindmap(labelId, mindmapId);
|
||||
if (relationship == null) {
|
||||
throw new LabelMindmapRelationshipNotFoundException("Label Map relation could not be found. Label Id: " + labelId + ", Map Id: " + mindmapId);
|
||||
}
|
||||
labelMindmapService.removeLabelFromMindmap(relationship);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package com.wisemapping.rest.model;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.wisemapping.model.LabelMindmap;
|
||||
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
|
||||
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
|
||||
|
||||
@JsonAutoDetect(
|
||||
fieldVisibility = NONE,
|
||||
setterVisibility = PUBLIC_ONLY,
|
||||
isGetterVisibility = NONE,
|
||||
getterVisibility = PUBLIC_ONLY
|
||||
)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RestLabelMindmap {
|
||||
|
||||
@JsonIgnore
|
||||
private LabelMindmap labelMindmap;
|
||||
|
||||
public RestLabelMindmap() {
|
||||
this(new LabelMindmap());
|
||||
}
|
||||
|
||||
public RestLabelMindmap(@NotNull final LabelMindmap labelMindmap) {
|
||||
this.labelMindmap = labelMindmap;
|
||||
}
|
||||
|
||||
public void setLabelId(final int labelId) {
|
||||
this.labelMindmap.setLabelId(labelId);
|
||||
}
|
||||
|
||||
public int getLabelId() {
|
||||
return this.labelMindmap.getLabelId();
|
||||
}
|
||||
|
||||
public void setMindmapId(final int mindmapId) {
|
||||
labelMindmap.setMindmapId(mindmapId);
|
||||
}
|
||||
|
||||
public int getMindmapId() {
|
||||
return this.labelMindmap.getMindmapId();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.wisemapping.service;
|
||||
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.Label;
|
||||
import com.wisemapping.model.LabelMindmap;
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public interface LabelMindmapService {
|
||||
|
||||
void removeLabelFromMindmap(@NotNull final LabelMindmap labelMindmap) throws WiseMappingException;
|
||||
|
||||
LabelMindmap getLabelMindmap(int labelId, int mindmapId);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package com.wisemapping.service;
|
||||
|
||||
import com.wisemapping.dao.LabelMindmapManager;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.LabelMindmap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LabelMindmapServiceImpl implements LabelMindmapService {
|
||||
|
||||
private LabelMindmapManager labelMindmapManager;
|
||||
|
||||
public void setLabelMindmapManager(LabelMindmapManager labelMindmapManager) {
|
||||
this.labelMindmapManager = labelMindmapManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLabelFromMindmap(@NotNull LabelMindmap labelMindmap) throws WiseMappingException {
|
||||
this.labelMindmapManager.removeLabelMindmap(labelMindmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelMindmap getLabelMindmap(int labelId, int mindmapId) {
|
||||
return this.labelMindmapManager.getLabelMindmap(labelId, mindmapId);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user