allow empty names for modification requests, not modifying the name (fix #263)

This commit is contained in:
Athou
2013-06-05 20:51:29 +02:00
parent db6915ed59
commit 7943c8e1e6
4 changed files with 16 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ public class CategoryModificationRequest implements Serializable {
@ApiProperty(value = "id", required = true) @ApiProperty(value = "id", required = true)
private Long id; private Long id;
@ApiProperty(value = "new name") @ApiProperty(value = "new name, null if not changed")
private String name; private String name;
@ApiProperty(value = "new parent category id") @ApiProperty(value = "new parent category id")

View File

@@ -18,7 +18,7 @@ public class FeedModificationRequest implements Serializable {
@ApiProperty(value = "id", required = true) @ApiProperty(value = "id", required = true)
private Long id; private Long id;
@ApiProperty(value = "new name") @ApiProperty(value = "new name, null if not changed")
private String name; private String name;
@ApiProperty(value = "new parent category id") @ApiProperty(value = "new parent category id")

View File

@@ -252,11 +252,13 @@ public class CategoryREST extends AbstractResourceREST {
@ApiParam(required = true) CategoryModificationRequest req) { @ApiParam(required = true) CategoryModificationRequest req) {
Preconditions.checkNotNull(req); Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId()); Preconditions.checkNotNull(req.getId());
Preconditions.checkArgument(StringUtils.isNotBlank(req.getName()));
FeedCategory category = feedCategoryDAO FeedCategory category = feedCategoryDAO
.findById(getUser(), req.getId()); .findById(getUser(), req.getId());
category.setName(req.getName());
if (StringUtils.isNotBlank(req.getName())) {
category.setName(req.getName());
}
FeedCategory parent = null; FeedCategory parent = null;
if (req.getParentId() != null if (req.getParentId() != null
@@ -274,7 +276,8 @@ public class CategoryREST extends AbstractResourceREST {
Collections.sort(categories, new Comparator<FeedCategory>() { Collections.sort(categories, new Comparator<FeedCategory>() {
@Override @Override
public int compare(FeedCategory o1, FeedCategory o2) { public int compare(FeedCategory o1, FeedCategory o2) {
return ObjectUtils.compare(o1.getPosition(), o2.getPosition()); return ObjectUtils.compare(o1.getPosition(),
o2.getPosition());
} }
}); });

View File

@@ -317,11 +317,13 @@ public class FeedREST extends AbstractResourceREST {
@ApiParam(value = "subscription id", required = true) FeedModificationRequest req) { @ApiParam(value = "subscription id", required = true) FeedModificationRequest req) {
Preconditions.checkNotNull(req); Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId()); Preconditions.checkNotNull(req.getId());
Preconditions.checkNotNull(req.getName());
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(),
req.getId()); req.getId());
subscription.setTitle(req.getName());
if (StringUtils.isNotBlank(req.getName())) {
subscription.setTitle(req.getName());
}
FeedCategory parent = null; FeedCategory parent = null;
if (req.getCategoryId() != null if (req.getCategoryId() != null
@@ -337,7 +339,8 @@ public class FeedREST extends AbstractResourceREST {
Collections.sort(subs, new Comparator<FeedSubscription>() { Collections.sort(subs, new Comparator<FeedSubscription>() {
@Override @Override
public int compare(FeedSubscription o1, FeedSubscription o2) { public int compare(FeedSubscription o1, FeedSubscription o2) {
return ObjectUtils.compare(o1.getPosition(), o2.getPosition()); return ObjectUtils.compare(o1.getPosition(),
o2.getPosition());
} }
}); });