mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-09 00:43:23 +01:00
retrieveList api for labels
This commit is contained in:
parent
0c43bb4ad3
commit
306a2a2ada
@ -1,6 +1,7 @@
|
|||||||
package com.wisemapping.dao;
|
package com.wisemapping.dao;
|
||||||
|
|
||||||
import com.wisemapping.model.Label;
|
import com.wisemapping.model.Label;
|
||||||
|
import com.wisemapping.model.User;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,4 +12,6 @@ public interface LabelManager {
|
|||||||
|
|
||||||
void saveLabel(@NotNull final Label label);
|
void saveLabel(@NotNull final Label label);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
List<Label> getAllLabels(@NotNull final User user);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.wisemapping.dao;
|
package com.wisemapping.dao;
|
||||||
|
|
||||||
import com.wisemapping.model.Label;
|
import com.wisemapping.model.Label;
|
||||||
|
import com.wisemapping.model.User;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LabelManagerImpl extends HibernateDaoSupport
|
public class LabelManagerImpl extends HibernateDaoSupport
|
||||||
implements LabelManager {
|
implements LabelManager {
|
||||||
|
|
||||||
@ -16,4 +19,10 @@ public class LabelManagerImpl extends HibernateDaoSupport
|
|||||||
public void saveLabel(@NotNull final Label label) {
|
public void saveLabel(@NotNull final Label label) {
|
||||||
getSession().save(label);
|
getSession().save(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<Label> getAllLabels(@NotNull final User user) {
|
||||||
|
return getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where creator_id=?", user.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 com.wisemapping.rest.model.RestLabel;
|
import com.wisemapping.rest.model.RestLabel;
|
||||||
|
import com.wisemapping.rest.model.RestLabelList;
|
||||||
import com.wisemapping.security.Utils;
|
import com.wisemapping.security.Utils;
|
||||||
import com.wisemapping.service.LabelService;
|
import com.wisemapping.service.LabelService;
|
||||||
import com.wisemapping.validator.LabelValidator;
|
import com.wisemapping.validator.LabelValidator;
|
||||||
@ -21,6 +22,8 @@ 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;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class LabelController extends BaseController {
|
public class LabelController extends BaseController {
|
||||||
@ -44,7 +47,6 @@ public class LabelController extends BaseController {
|
|||||||
final BindingResult result = new BeanPropertyBindingResult(restLabel, "");
|
final BindingResult result = new BeanPropertyBindingResult(restLabel, "");
|
||||||
new LabelValidator().validate(label, result);
|
new LabelValidator().validate(label, result);
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
|
|
||||||
throw new ValidationException(result);
|
throw new ValidationException(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,4 +59,12 @@ public class LabelController extends BaseController {
|
|||||||
response.setHeader("ResourceId", Integer.toString(label.getId()));
|
response.setHeader("ResourceId", Integer.toString(label.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = "/labels", produces = {"application/json"})
|
||||||
|
public RestLabelList retrieveList() {
|
||||||
|
final User user = Utils.getUser();
|
||||||
|
assert user != null;
|
||||||
|
final List<Label> all = labelService.getAll(user);
|
||||||
|
return new RestLabelList(all);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ package com.wisemapping.rest.model;
|
|||||||
import com.wisemapping.model.Label;
|
import com.wisemapping.model.Label;
|
||||||
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@ -18,6 +21,7 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONL
|
|||||||
isGetterVisibility = NONE,
|
isGetterVisibility = NONE,
|
||||||
getterVisibility = PUBLIC_ONLY
|
getterVisibility = PUBLIC_ONLY
|
||||||
)
|
)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class RestLabel {
|
public class RestLabel {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@ -32,6 +36,15 @@ public class RestLabel {
|
|||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setParent(@NotNull final Label parent) {
|
||||||
|
this.label.setParent(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Label getParent() {
|
||||||
|
return this.label.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return this.label.getTitle();
|
return this.label.getTitle();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.wisemapping.rest.model;
|
||||||
|
|
||||||
|
import com.wisemapping.model.Label;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RestLabelList {
|
||||||
|
|
||||||
|
@NotNull private final List<RestLabel> restLabels;
|
||||||
|
|
||||||
|
public RestLabelList(@NotNull final List<Label> labels) {
|
||||||
|
this.restLabels = new ArrayList<>(labels.size());
|
||||||
|
for (Label label : labels) {
|
||||||
|
this.restLabels.add(new RestLabel(label));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull @XmlElement(name = "label")
|
||||||
|
public List<RestLabel> getLabels() {
|
||||||
|
return restLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,8 +5,11 @@ 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 java.util.List;
|
||||||
|
|
||||||
public interface LabelService {
|
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);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ 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 java.util.List;
|
||||||
|
|
||||||
public class LabelServiceImpl implements LabelService {
|
public class LabelServiceImpl implements LabelService {
|
||||||
|
|
||||||
private LabelManager labelManager;
|
private LabelManager labelManager;
|
||||||
@ -21,4 +23,10 @@ public class LabelServiceImpl implements LabelService {
|
|||||||
labelManager.addLabel(label);
|
labelManager.addLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<Label> getAll(@NotNull final User user) {
|
||||||
|
return labelManager.getAllLabels(user);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user