ALF-9156 Calendar Java API tagging support, and convert the Event Get webscript to be java backed

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28840 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-07-06 17:14:52 +00:00
parent d1c6383f6e
commit 32938984cb
4 changed files with 191 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ package org.alfresco.repo.calendar;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.service.cmr.calendar.CalendarEntry; import org.alfresco.service.cmr.calendar.CalendarEntry;
@@ -99,7 +100,9 @@ public class CalendarEntryImpl extends CalendarEntryDTO
entry.setEnd((Date)properties.get(CalendarModel.PROP_TO_DATE)); entry.setEnd((Date)properties.get(CalendarModel.PROP_TO_DATE));
entry.setRecurrenceRule((String)properties.get(CalendarModel.PROP_RECURRENCE_RULE)); entry.setRecurrenceRule((String)properties.get(CalendarModel.PROP_RECURRENCE_RULE));
entry.setLastRecurrence((Date)properties.get(CalendarModel.PROP_RECURRENCE_LAST_MEETING)); entry.setLastRecurrence((Date)properties.get(CalendarModel.PROP_RECURRENCE_LAST_MEETING));
entry.setOutlook((Boolean)properties.get(CalendarModel.PROP_IS_OUTLOOK));
Boolean isOutlook = (Boolean)properties.get(CalendarModel.PROP_IS_OUTLOOK);
entry.setOutlook(isOutlook == null ? false : isOutlook);
entry.setOutlookUID((String)properties.get(CalendarModel.PROP_OUTLOOK_UID)); entry.setOutlookUID((String)properties.get(CalendarModel.PROP_OUTLOOK_UID));
//entry.setColor(properties.get(CalendarModel.PROP_COLOR)); //entry.setColor(properties.get(CalendarModel.PROP_COLOR));
@@ -114,4 +117,13 @@ public class CalendarEntryImpl extends CalendarEntryDTO
{ {
populate(this, properties); populate(this, properties);
} }
/**
* Sets the list of tags for the entry
*/
protected void setTags(List<String> tags)
{
super.getTags().clear();
super.getTags().addAll(tags);
}
} }

View File

@@ -19,7 +19,12 @@
package org.alfresco.repo.calendar; package org.alfresco.repo.calendar;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
@@ -178,6 +183,54 @@ public class CalendarServiceImpl implements CalendarService
} }
} }
private void handleTags(CalendarEntry entry)
{
NodeRef nodeRef = entry.getNodeRef();
List<String> currentTags = taggingService.getTags(nodeRef);
List<String> newTags = entry.getTags();
if(currentTags.size() == 0 && newTags.size() == 0)
{
// No tags, easy
return;
}
// Figure out what (if anything) changed
Set<String> toAdd = new HashSet<String>(newTags);
Set<String> toDel = new HashSet<String>(currentTags);
for(String tag : currentTags)
{
if(toAdd.contains(tag))
{
toAdd.remove(tag);
}
}
for(String tag : newTags)
{
if(toDel.contains(tag))
{
toDel.remove(tag);
}
}
if(toDel.size() == 0 && toAdd.size() == 0)
{
// No changes
}
// Make the changes
taggingService.clearTags(nodeRef);
for(String tag : toDel)
{
taggingService.removeTag(nodeRef, tag);
}
for(String tag : toAdd)
{
taggingService.addTag(nodeRef, tag);
}
}
@Override @Override
public CalendarEntry getCalendarEntry(String siteShortName, String entryName) public CalendarEntry getCalendarEntry(String siteShortName, String entryName)
{ {
@@ -193,6 +246,7 @@ public class CalendarServiceImpl implements CalendarService
{ {
CalendarEntryImpl entry = new CalendarEntryImpl(event, entryName); CalendarEntryImpl entry = new CalendarEntryImpl(event, entryName);
entry.populate(nodeService.getProperties(event)); entry.populate(nodeService.getProperties(event));
entry.setTags(taggingService.getTags(event));
return entry; return entry;
} }
return null; return null;
@@ -212,8 +266,10 @@ public class CalendarServiceImpl implements CalendarService
// Turn the entry into properties // Turn the entry into properties
Map<QName,Serializable> properties = CalendarEntryImpl.toNodeProperties(entry); Map<QName,Serializable> properties = CalendarEntryImpl.toNodeProperties(entry);
// Generate a name // Generate a unique name
String name = "123.ics"; // TODO // (Should be unique, but will retry for a new one if not)
String name = (new Date()).getTime() + "-" +
Math.round(Math.random()*10000) + ".ics";
properties.put(ContentModel.PROP_NAME, name); properties.put(ContentModel.PROP_NAME, name);
// Add the entry // Add the entry
@@ -236,7 +292,13 @@ public class CalendarServiceImpl implements CalendarService
{ {
entryImpl = new CalendarEntryImpl(nodeRef, name); entryImpl = new CalendarEntryImpl(nodeRef, name);
entryImpl.populate(properties); entryImpl.populate(properties);
entryImpl.setTags(entry.getTags());
} }
// Tag it
handleTags(entryImpl);
// All done
return entryImpl; return entryImpl;
} }
@@ -252,6 +314,9 @@ public class CalendarServiceImpl implements CalendarService
// Update the existing one // Update the existing one
nodeService.setProperties(entry.getNodeRef(), properties); nodeService.setProperties(entry.getNodeRef(), properties);
// Update tags
handleTags(entry);
// Nothing changed // Nothing changed
return entry; return entry;
} }

View File

@@ -321,6 +321,115 @@ public class CalendarServiceImplTest
}); });
} }
@Test public void tagging() throws Exception
{
CalendarEntry entry;
final String TAG_1 = "calendar_tag_1";
final String TAG_2 = "calendar_tag_2";
final String TAG_3 = "calendar_tag_3";
// Create one without tagging
entry = new CalendarEntryDTO(
"Title", "Description", "Location", new Date(1), new Date(1234)
);
entry = CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), entry);
// Check
assertEquals(0, entry.getTags().size());
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(0, entry.getTags().size());
// Update it to have tags
entry.getTags().add(TAG_1);
entry.getTags().add(TAG_2);
entry.getTags().add(TAG_1);
assertEquals(3, entry.getTags().size());
CALENDAR_SERVICE.updateCalendarEntry(entry);
// Check
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(2, entry.getTags().size());
assertEquals(true, entry.getTags().contains(TAG_1));
assertEquals(true, entry.getTags().contains(TAG_2));
assertEquals(false, entry.getTags().contains(TAG_3));
// Update it to have different tags
entry.getTags().remove(TAG_2);
entry.getTags().add(TAG_3);
entry.getTags().add(TAG_1);
CALENDAR_SERVICE.updateCalendarEntry(entry);
// Check
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(2, entry.getTags().size());
assertEquals(true, entry.getTags().contains(TAG_1));
assertEquals(false, entry.getTags().contains(TAG_2));
assertEquals(true, entry.getTags().contains(TAG_3));
// Update it to have no tags
entry.getTags().clear();
CALENDAR_SERVICE.updateCalendarEntry(entry);
// Check
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(0, entry.getTags().size());
// Update it to have tags again
entry.getTags().add(TAG_1);
entry.getTags().add(TAG_2);
entry.getTags().add(TAG_3);
CALENDAR_SERVICE.updateCalendarEntry(entry);
// Check
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(3, entry.getTags().size());
assertEquals(true, entry.getTags().contains(TAG_1));
assertEquals(true, entry.getTags().contains(TAG_2));
assertEquals(true, entry.getTags().contains(TAG_3));
// Tidy
CALENDAR_SERVICE.deleteCalendarEntry(entry);
// Create an event with tags
entry = new CalendarEntryDTO(
"Title", "Description", "Location", new Date(1), new Date(1234)
);
entry.getTags().add(TAG_1);
entry.getTags().add(TAG_1);
entry.getTags().add(TAG_2);
entry = CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), entry);
// Check
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(2, entry.getTags().size());
assertEquals(true, entry.getTags().contains(TAG_1));
assertEquals(true, entry.getTags().contains(TAG_2));
assertEquals(false, entry.getTags().contains(TAG_3));
// Update it to have different tags
entry.getTags().remove(TAG_2);
entry.getTags().add(TAG_3);
entry.getTags().add(TAG_1);
CALENDAR_SERVICE.updateCalendarEntry(entry);
// Check
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
assertEquals(2, entry.getTags().size());
assertEquals(true, entry.getTags().contains(TAG_1));
assertEquals(false, entry.getTags().contains(TAG_2));
assertEquals(true, entry.getTags().contains(TAG_3));
// Tidy
CALENDAR_SERVICE.deleteCalendarEntry(entry);
}
@Test public void calendarListing() throws Exception @Test public void calendarListing() throws Exception
{ {
// TODO // TODO

View File

@@ -19,6 +19,7 @@
package org.alfresco.service.cmr.calendar; package org.alfresco.service.cmr.calendar;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -44,7 +45,7 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable {
private Date lastRecurrence; private Date lastRecurrence;
private boolean isOutlook = false; private boolean isOutlook = false;
private String outlookUID; private String outlookUID;
private List<String> tags; private List<String> tags = new ArrayList<String>();
/** /**
* Creates an empty {@link CalendarEntry}, which can be populated * Creates an empty {@link CalendarEntry}, which can be populated
@@ -233,7 +234,6 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable {
*/ */
public List<String> getTags() public List<String> getTags()
{ {
// TODO Immutable?
return tags; return tags;
} }