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)
private Long id;
@ApiProperty(value = "new name")
@ApiProperty(value = "new name, null if not changed")
private String name;
@ApiProperty(value = "new parent category id")

View File

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

View File

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

View File

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