mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-22 00:26:05 +08:00
Merge branch 'github_dev' of https://github.com/ctripcorp/zeus into github_dev
This commit is contained in:
commit
a0adf2f9ad
|
@ -6,6 +6,7 @@ import com.ctrip.zeus.tag.PropertyBox;
|
|||
import com.ctrip.zeus.tag.PropertyService;
|
||||
import com.ctrip.zeus.tag.entity.Property;
|
||||
import com.ctrip.zeus.tag.entity.PropertyList;
|
||||
import com.google.common.base.Joiner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -39,10 +40,10 @@ public class PropertyResource {
|
|||
public Response listProperties(@Context HttpHeaders hh,
|
||||
@Context HttpServletRequest request,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("id") Long id) throws Exception {
|
||||
@QueryParam("targetId") Long targetId) throws Exception {
|
||||
List<Property> list;
|
||||
if (type != null && id != null) {
|
||||
list = propertyService.getProperties(type, id);
|
||||
if (type != null && targetId != null) {
|
||||
list = propertyService.getProperties(type, targetId);
|
||||
} else {
|
||||
list = propertyBox.getAllProperties();
|
||||
}
|
||||
|
@ -92,11 +93,11 @@ public class PropertyResource {
|
|||
@QueryParam("pname") String pname,
|
||||
@QueryParam("pvalue") String pvalue,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("id") Long id) throws Exception {
|
||||
if (pname == null || pvalue == null || type == null || id == null)
|
||||
@QueryParam("targetId") List<Long> targetIds) throws Exception {
|
||||
if (pname == null || pvalue == null || type == null || targetIds == null)
|
||||
throw new ValidationException("At least one parameter is missing.");
|
||||
propertyBox.add(pname, pvalue, type, id);
|
||||
return responseHandler.handle(id + " is added to property " + pname + "/" + pvalue + ".", hh.getMediaType());
|
||||
propertyBox.add(pname, pvalue, type, targetIds.toArray(new Long[targetIds.size()]));
|
||||
return responseHandler.handle(Joiner.on(", ").join(targetIds) + " is added to property " + pname + "/" + pvalue + ".", hh.getMediaType());
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -107,13 +108,13 @@ public class PropertyResource {
|
|||
@QueryParam("pname") String pname,
|
||||
@QueryParam("pvalue") String pvalue,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("id") Long id,
|
||||
@QueryParam("targetId") List<Long> targetIds,
|
||||
@QueryParam("batch") Boolean batch) throws Exception {
|
||||
if ((pname == null && pvalue == null) || type == null)
|
||||
throw new ValidationException("At least one parameter is missing.");
|
||||
if (id != null) {
|
||||
propertyBox.delete(pname, pvalue, type, id);
|
||||
return responseHandler.handle(id + " is deleted from property " + pname + "/" + pvalue + ".", hh.getMediaType());
|
||||
if (targetIds != null) {
|
||||
propertyBox.delete(pname, pvalue, type, targetIds.toArray(new Long[targetIds.size()]));
|
||||
return responseHandler.handle(Joiner.on(", ").join(targetIds) + " is deleted from property " + pname + "/" + pvalue + ".", hh.getMediaType());
|
||||
}
|
||||
if (batch != null && batch.booleanValue()) {
|
||||
propertyBox.delete(pname, pvalue, type, null);
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.ctrip.zeus.restful.message.ResponseHandler;
|
|||
import com.ctrip.zeus.tag.TagBox;
|
||||
import com.ctrip.zeus.tag.TagService;
|
||||
import com.ctrip.zeus.tag.entity.TagList;
|
||||
import com.google.common.base.Joiner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -38,10 +39,10 @@ public class TagResource {
|
|||
public Response listTags(@Context HttpHeaders hh,
|
||||
@Context HttpServletRequest request,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("id") Long id) throws Exception {
|
||||
@QueryParam("targetId") Long targetId) throws Exception {
|
||||
List<String> list;
|
||||
if (type != null && id != null) {
|
||||
list = tagService.getTags(type, id);
|
||||
if (type != null && targetId != null) {
|
||||
list = tagService.getTags(type, targetId);
|
||||
} else {
|
||||
list = tagBox.getAllTags();
|
||||
}
|
||||
|
@ -72,11 +73,11 @@ public class TagResource {
|
|||
@Context HttpServletRequest request,
|
||||
@QueryParam("tagName") String tagName,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("id") Long id) throws Exception {
|
||||
if (tagName == null || type == null || id == null)
|
||||
@QueryParam("targetId") List<Long> targetIds) throws Exception {
|
||||
if (tagName == null || type == null || targetIds == null)
|
||||
throw new ValidationException("At least one parameter is missing.");
|
||||
tagBox.tagging(tagName, type, id);
|
||||
return responseHandler.handle("Tagged " + id + " to " + tagName + ".", hh.getMediaType());
|
||||
tagBox.tagging(tagName, type, targetIds.toArray(new Long[targetIds.size()]));
|
||||
return responseHandler.handle("Tagged " + Joiner.on(", ").join(targetIds) + " to " + tagName + ".", hh.getMediaType());
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -86,13 +87,13 @@ public class TagResource {
|
|||
@Context HttpServletRequest request,
|
||||
@QueryParam("tagName") String tagName,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("id") Long id,
|
||||
@QueryParam("targetId") List<Long> targetIds,
|
||||
@QueryParam("batch") Boolean batch) throws Exception {
|
||||
if (tagName == null)
|
||||
throw new ValidationException("Tag name is required.");
|
||||
if (type != null && id != null) {
|
||||
tagBox.untagging(tagName, type, id);
|
||||
return responseHandler.handle("Untagged " + id + " from " + tagName + ".", hh.getMediaType());
|
||||
if (type != null && targetIds != null) {
|
||||
tagBox.untagging(tagName, type, targetIds.toArray(new Long[targetIds.size()]));
|
||||
return responseHandler.handle("Untagged " + Joiner.on(", ").join(targetIds) + " from " + tagName + ".", hh.getMediaType());
|
||||
}
|
||||
if (batch != null && batch.booleanValue()) {
|
||||
if (type != null) {
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface PropertyBox {
|
|||
|
||||
void renameProperty(String oldName, String newName, String oldValue, String newValue) throws Exception;
|
||||
|
||||
void add(String pname, String pvalue, String type, Long itemId) throws Exception;
|
||||
void add(String pname, String pvalue, String type, Long[] itemIds) throws Exception;
|
||||
|
||||
void delete(String pname, String pvalue, String type, Long itemId) throws Exception;
|
||||
void delete(String pname, String pvalue, String type, Long[] itemIds) throws Exception;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public interface TagBox {
|
|||
|
||||
void renameTag(String oldName, String newName) throws Exception;
|
||||
|
||||
void tagging(String tagName, String type, Long itemId) throws Exception;
|
||||
void tagging(String tagName, String type, Long[] itemIds) throws Exception;
|
||||
|
||||
void untagging(String tagName, String type, Long itemId) throws Exception;
|
||||
void untagging(String tagName, String type, Long[] itemIds) throws Exception;
|
||||
}
|
|
@ -78,7 +78,7 @@ public class DefaultPropertyBox implements PropertyBox {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void add(String pname, String pvalue, String type, Long itemId) throws Exception {
|
||||
public void add(String pname, String pvalue, String type, Long[] itemIds) throws Exception {
|
||||
PropertyKeyDo kd = propertyKeyDao.findByName(pname, PropertyKeyEntity.READSET_FULL);
|
||||
PropertyDo d = null;
|
||||
if (kd == null) {
|
||||
|
@ -91,19 +91,28 @@ public class DefaultPropertyBox implements PropertyBox {
|
|||
d = new PropertyDo().setPropertyKeyId(kd.getId()).setPropertyValue(pvalue);
|
||||
propertyDao.insert(d);
|
||||
}
|
||||
propertyItemDao.insert(new PropertyItemDo().setPropertyId(d.getId()).setType(type).setItemId(itemId));
|
||||
PropertyItemDo[] l = new PropertyItemDo[itemIds.length];
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
l[i] = new PropertyItemDo().setPropertyId(d.getId()).setType(type).setItemId(itemIds[i]);
|
||||
}
|
||||
propertyItemDao.insert(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String pname, String pvalue, String type, Long itemId) throws Exception {
|
||||
public void delete(String pname, String pvalue, String type, Long[] itemIds) throws Exception {
|
||||
PropertyKeyDo kd = propertyKeyDao.findByName(pname, PropertyKeyEntity.READSET_FULL);
|
||||
if (kd == null)
|
||||
return;
|
||||
PropertyDo d = propertyDao.findByKeyAndValue(kd.getId(), pvalue, PropertyEntity.READSET_FULL);
|
||||
if (d == null)
|
||||
return;
|
||||
if (itemId != null)
|
||||
propertyItemDao.deleteByPropertyAndItem(new PropertyItemDo().setPropertyId(d.getId()).setType(type).setItemId(itemId));
|
||||
if (itemIds != null) {
|
||||
PropertyItemDo[] l = new PropertyItemDo[itemIds.length];
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
l[i] = new PropertyItemDo().setPropertyId(d.getId()).setType(type).setItemId(itemIds[i]);
|
||||
}
|
||||
propertyItemDao.deleteByPropertyAndItems(l);
|
||||
}
|
||||
else
|
||||
propertyItemDao.deleteByPropertyAndType(new PropertyItemDo().setPropertyId(d.getId()).setType(type));
|
||||
}
|
||||
|
|
|
@ -46,27 +46,33 @@ public class DefaultTagBox implements TagBox {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void tagging(String tagName, String type, Long itemId) throws Exception {
|
||||
public void tagging(String tagName, String type, Long[] itemIds) throws Exception {
|
||||
TagDo d = tagDao.findByName(tagName, TagEntity.READSET_FULL);
|
||||
if (d == null) {
|
||||
d = new TagDo().setName(tagName);
|
||||
tagDao.insert(d);
|
||||
}
|
||||
tagItemDao.insert(new TagItemDo().setTagId(d.getId()).setType(type).setItemId(itemId));
|
||||
TagItemDo[] l = new TagItemDo[itemIds.length];
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
l[i] = new TagItemDo().setTagId(d.getId()).setType(type).setItemId(itemIds[i]);
|
||||
}
|
||||
tagItemDao.insert(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untagging(String tagName, String type, Long itemId) throws Exception {
|
||||
public void untagging(String tagName, String type, Long[] itemIds) throws Exception {
|
||||
TagDo d = tagDao.findByName(tagName, TagEntity.READSET_FULL);
|
||||
if (d == null) {
|
||||
throw new ValidationException("Tag named " + tagName + "is not found.");
|
||||
}
|
||||
TagItemDo tid = new TagItemDo().setTagId(d.getId()).setType(type);
|
||||
if (itemId != null) {
|
||||
tid.setItemId(itemId);
|
||||
tagItemDao.deleteTagItem(tid);
|
||||
if (itemIds != null) {
|
||||
TagItemDo[] l = new TagItemDo[itemIds.length];
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
l[i] = new TagItemDo().setTagId(d.getId()).setType(type).setItemId(itemIds[i]);
|
||||
}
|
||||
tagItemDao.deleteTagItems(l);
|
||||
} else {
|
||||
tagItemDao.deleteTagType(tid);
|
||||
tagItemDao.deleteTagType(new TagItemDo().setTagId(d.getId()).setType(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="insert" type="INSERT">
|
||||
<query name="insert" type="INSERT" batch="true">
|
||||
<statement>
|
||||
<![CDATA[
|
||||
INSERT INTO <TABLE/>(<FIELDS/>)
|
||||
|
@ -101,7 +101,7 @@
|
|||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="delete-tag-item" type="DELETE">
|
||||
<query name="delete-tag-items" type="DELETE" batch="true">
|
||||
<param name="tag-id"/>
|
||||
<param name="type"/>
|
||||
<param name="item-id"/>
|
||||
|
@ -274,7 +274,7 @@
|
|||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="insert" type="INSERT">
|
||||
<query name="insert" type="INSERT" batch="true">
|
||||
<statement>
|
||||
<![CDATA[
|
||||
INSERT INTO <TABLE/>(<FIELDS/>)
|
||||
|
@ -282,7 +282,7 @@
|
|||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="delete-by-property-and-item" type="DELETE">
|
||||
<query name="delete-by-property-and-items" type="DELETE" batch="true">
|
||||
<param name="property-id"/>
|
||||
<param name="item-id"/>
|
||||
<statement>
|
||||
|
|
|
@ -38,20 +38,20 @@ public class PropertyTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testAddAndRemoveItem() throws Exception {
|
||||
propertyBox.add("department", "qiche", "client", 1L);
|
||||
propertyBox.add("department", "gonglue", "client", 1L);
|
||||
propertyBox.add("department", "qiche", "client", 2L);
|
||||
propertyBox.add("department", "jiudian", "client", 5L);
|
||||
propertyBox.add("department", "qiche", "client", 3L);
|
||||
propertyBox.add("department", "gonglue", "client", 6L);
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{1L});
|
||||
propertyBox.add("department", "gonglue", "client", new Long[]{1L});
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{2L});
|
||||
propertyBox.add("department", "jiudian", "client", new Long[]{5L});
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{3L});
|
||||
propertyBox.add("department", "gonglue", "client", new Long[]{6L});
|
||||
|
||||
List<Long> plist = propertyService.query("department", "client");
|
||||
Assert.assertEquals(6, plist.size());
|
||||
plist = propertyService.query("department", "qiche", "client");
|
||||
Assert.assertEquals(3, plist.size());
|
||||
|
||||
propertyBox.delete("department", "qiche", "client", 3L);
|
||||
propertyBox.delete("department", "qiche", "client", 1L);
|
||||
propertyBox.delete("department", "qiche", "client", new Long[]{3L});
|
||||
propertyBox.delete("department", "qiche", "client", new Long[]{1L});
|
||||
plist = propertyService.query("department", "qiche", "client");
|
||||
Assert.assertEquals(1, plist.size());
|
||||
|
||||
|
@ -64,15 +64,15 @@ public class PropertyTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testRenameProperty() throws Exception {
|
||||
propertyBox.add("bumen", "car", "client", 1L);
|
||||
propertyBox.add("bumen", "car", "client", new Long[]{1L});
|
||||
propertyBox.renameProperty("bumen", "department", "car", "qiche");
|
||||
List<Long> plist = propertyService.query("bumen", "qiche", "client");
|
||||
Assert.assertEquals(0, plist.size());
|
||||
plist = propertyService.query("department", "qiche", "client");
|
||||
Assert.assertEquals(1, plist.size());
|
||||
|
||||
propertyBox.add("department", "qiche", "client", 3L);
|
||||
propertyBox.add("department", "qiche", "client", 2L);
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{3L});
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{2L});
|
||||
propertyBox.renameProperty("department", "bumen");
|
||||
plist = propertyService.query("bumen", "qiche", "client");
|
||||
Assert.assertEquals(3, plist.size());
|
||||
|
@ -82,12 +82,12 @@ public class PropertyTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testGetItemProperties() throws Exception {
|
||||
propertyBox.add("department", "qiche", "client", 1L);
|
||||
propertyBox.add("department", "gonglue", "client", 1L);
|
||||
propertyBox.add("department", "qiche", "client", 2L);
|
||||
propertyBox.add("department", "jiudian", "client", 1L);
|
||||
propertyBox.add("department", "qiche", "client", 3L);
|
||||
propertyBox.add("department", "gonglue", "client", 6L);
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{1L});
|
||||
propertyBox.add("department", "gonglue", "client", new Long[]{1L});
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{2L});
|
||||
propertyBox.add("department", "jiudian", "client", new Long[]{1L});
|
||||
propertyBox.add("department", "qiche", "client", new Long[]{3L});
|
||||
propertyBox.add("department", "gonglue", "client", new Long[]{6L});
|
||||
|
||||
List<Property> l = propertyService.getProperties("client", 1L);
|
||||
Assert.assertEquals(1, l.size());
|
||||
|
|
|
@ -37,25 +37,25 @@ public class TagTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testTaggingAndUntagging() throws Exception {
|
||||
tagBox.tagging("testTaggingGroup", "group", 1L);
|
||||
tagBox.tagging("testTaggingGroup", "group", 2L);
|
||||
tagBox.tagging("testTaggingGroup", "group", 3L);
|
||||
tagBox.tagging("testTaggingSlb", "slb", 1L);
|
||||
tagBox.tagging("testTaggingSlb", "slb", 2L);
|
||||
tagBox.tagging("testTaggingSlb", "slb", 3L);
|
||||
tagBox.tagging("testTaggingSlb", "slb", 4L);
|
||||
tagBox.tagging("testTaggingSlb", "slb", 5L);
|
||||
tagBox.tagging("testTaggingGroup", "group", new Long[]{1L});
|
||||
tagBox.tagging("testTaggingGroup", "group", new Long[]{2L});
|
||||
tagBox.tagging("testTaggingGroup", "group", new Long[]{3L});
|
||||
tagBox.tagging("testTaggingSlb", "slb", new Long[]{1L});
|
||||
tagBox.tagging("testTaggingSlb", "slb", new Long[]{2L});
|
||||
tagBox.tagging("testTaggingSlb", "slb", new Long[]{3L});
|
||||
tagBox.tagging("testTaggingSlb", "slb", new Long[]{4L});
|
||||
tagBox.tagging("testTaggingSlb", "slb", new Long[]{5L});
|
||||
|
||||
List<Long> glist = tagService.query("testTaggingGroup", "group");
|
||||
List<Long> slist = tagService.query("testTaggingSlb", "slb");
|
||||
Assert.assertEquals(3, glist.size());
|
||||
Assert.assertEquals(5, slist.size());
|
||||
|
||||
tagBox.untagging("testTaggingGroup", "group", 2L);
|
||||
tagBox.untagging("testTaggingGroup", "group", 3L);
|
||||
tagBox.untagging("testTaggingSlb", "slb", 1L);
|
||||
tagBox.untagging("testTaggingSlb", "slb", 2L);
|
||||
tagBox.untagging("testTaggingSlb", "slb", 3L);
|
||||
tagBox.untagging("testTaggingGroup", "group", new Long[]{2L});
|
||||
tagBox.untagging("testTaggingGroup", "group", new Long[]{3L});
|
||||
tagBox.untagging("testTaggingSlb", "slb", new Long[]{1L});
|
||||
tagBox.untagging("testTaggingSlb", "slb", new Long[]{2L});
|
||||
tagBox.untagging("testTaggingSlb", "slb", new Long[]{3L});
|
||||
|
||||
glist = tagService.query("testTaggingGroup", "group");
|
||||
slist = tagService.query("testTaggingSlb", "slb");
|
||||
|
@ -77,9 +77,9 @@ public class TagTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testRenameTag() throws Exception {
|
||||
tagBox.tagging("testTaggingGroup", "group", 1L);
|
||||
tagBox.tagging("testTaggingGroup", "group", 2L);
|
||||
tagBox.tagging("testTaggingGroup", "group", 3L);
|
||||
tagBox.tagging("testTaggingGroup", "group", new Long[]{1L});
|
||||
tagBox.tagging("testTaggingGroup", "group", new Long[]{2L});
|
||||
tagBox.tagging("testTaggingGroup", "group", new Long[]{3L});
|
||||
|
||||
List<Long> l = tagService.query("testTaggingGroup", "group");
|
||||
Assert.assertEquals(3, l.size());
|
||||
|
@ -95,9 +95,9 @@ public class TagTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testGetItemTags() throws Exception {
|
||||
tagBox.tagging("testTaggingGroup1", "group", 1L);
|
||||
tagBox.tagging("testTaggingGroup2", "group", 1L);
|
||||
tagBox.tagging("testTaggingGroup3", "group", 2L);
|
||||
tagBox.tagging("testTaggingGroup1", "group", new Long[]{1L});
|
||||
tagBox.tagging("testTaggingGroup2", "group", new Long[]{1L});
|
||||
tagBox.tagging("testTaggingGroup3", "group", new Long[]{2L});
|
||||
|
||||
List<String> l = tagService.getTags("group", 1L);
|
||||
Assert.assertEquals(2, l.size());
|
||||
|
|
Loading…
Reference in a new issue