use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.
the class NodeParentsRelation method readAll.
/**
* List child node's parent(s) based on (parent ->) child associations.
* Returns primary parent & also secondary parents, if any.
*
* @param childNodeId String id of child node
*/
@Override
@WebApiDescription(title = "Return a list of parent nodes based on child assocs")
public CollectionWithPagingInfo<Node> readAll(String childNodeId, Parameters parameters) {
NodeRef childNodeRef = nodes.validateOrLookupNode(childNodeId, null);
QNamePattern assocTypeQNameParam = RegexQNamePattern.MATCH_ALL;
Boolean isPrimary = null;
Query q = parameters.getQuery();
if (q != null) {
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS_PARENTS, null);
QueryHelper.walk(q, propertyWalker);
isPrimary = propertyWalker.getProperty(Nodes.PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
String assocTypeQNameStr = propertyWalker.getProperty(Nodes.PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
if (assocTypeQNameStr != null) {
assocTypeQNameParam = nodes.getAssocType(assocTypeQNameStr);
}
}
List<ChildAssociationRef> childAssocRefs = null;
if (assocTypeQNameParam.equals(RegexQNamePattern.MATCH_ALL)) {
childAssocRefs = nodeService.getParentAssocs(childNodeRef);
} else {
childAssocRefs = nodeService.getParentAssocs(childNodeRef, assocTypeQNameParam, RegexQNamePattern.MATCH_ALL);
}
return listNodeChildAssocs(childAssocRefs, parameters, isPrimary, false);
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.
the class PatchThumbnailsAsRenditionsGet method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
if (logger.isInfoEnabled()) {
logger.debug("Patching legacy thumbnails by applying appropriate rendition aspect");
}
List<NodeRef> resultNodeRefs = null;
ResultSet types = null;
try {
types = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, QUERY);
resultNodeRefs = types.getNodeRefs();
} finally {
if (types != null) {
types.close();
}
}
long patchedNodeRefs = 0;
for (NodeRef nodeRef : resultNodeRefs) {
if (nodeService.exists(nodeRef) == false || renditionService.isRendition(nodeRef)) {
continue;
}
// Now add one of the two aspects depending on parent location.
ChildAssociationRef sourceNode = renditionService.getSourceNode(nodeRef);
ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
QName aspectToApply;
if (primaryParent.getParentRef().equals(sourceNode.getParentRef())) {
aspectToApply = RenditionModel.ASPECT_HIDDEN_RENDITION;
} else {
aspectToApply = RenditionModel.ASPECT_VISIBLE_RENDITION;
}
if (logger.isDebugEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Applying aspect ").append(aspectToApply).append(" to node ").append(nodeRef);
logger.debug(msg.toString());
}
nodeService.addAspect(nodeRef, aspectToApply, null);
patchedNodeRefs++;
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("patchedNodeCount", new Long(patchedNodeRefs));
return model;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.
the class CommentsLibJs method getComments.
/**
* Returns all comment nodes for a given node.
* @return an array of comments.
*/
public static List<ChildAssociationRef> getComments(NodeRef node, ServiceRegistry services) {
List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>();
NodeRef commentsFolder = getCommentsFolder(node, services);
if (commentsFolder != null) {
List<ChildAssociationRef> children = services.getNodeService().getChildAssocs(commentsFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
if (!children.isEmpty()) {
result = children;
}
}
return result;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.
the class AbstractCalendarListingWebScript method handleRecurring.
/**
* Do what's needed for recurring events.
*
* @return If dates have been tweaked, and a sort may be required
*/
protected boolean handleRecurring(CalendarEntry entry, Map<String, Object> entryResult, List<Map<String, Object>> allResults, Date from, Date until, boolean repeatingFirstOnly) {
if (entry.getRecurrenceRule() == null) {
// Nothing to do
return false;
}
// If no date is given, start looking for occurrences from the event itself
if (from == null) {
from = entry.getStart();
}
// Should we limit ourselves?
if (!repeatingFirstOnly) {
if (until == null) {
// If no end date was given, only allow repeating instances
// for next 60 days, to keep the list sane
// (It's normally only used for a month view anyway)
Calendar c = Calendar.getInstance();
c.setTime(from);
c.add(Calendar.DATE, 60);
until = c.getTime();
}
}
// How long is it?
long duration = entry.getEnd().getTime() - entry.getStart().getTime();
// if some instances were deleted from series ignore them
Set<QName> childNodeTypeQNames = new HashSet<QName>();
childNodeTypeQNames.add(CalendarModel.TYPE_IGNORE_EVENT);
List<ChildAssociationRef> ignoreEventList = nodeService.getChildAssocs(entry.getNodeRef(), childNodeTypeQNames);
Set<Date> ignoredDates = new HashSet<Date>();
for (ChildAssociationRef ignoreEvent : ignoreEventList) {
NodeRef nodeRef = ignoreEvent.getChildRef();
Date ignoredDate = (Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_IGNORE_EVENT_DATE);
ignoredDates.add(ignoredDate);
}
// Get it's recurring instances
List<Date> dates = CalendarRecurrenceHelper.getRecurrencesOnOrAfter(entry, from, until, repeatingFirstOnly, ignoredDates);
if (dates == null) {
dates = new ArrayList<Date>();
}
// Add on the original event time itself if needed
if (entry.getStart().getTime() >= from.getTime()) {
if (dates.size() == 0 || dates.get(0).getTime() != entry.getStart().getTime()) {
// Original event is after the start time, and not on the recurring list
dates.add(0, entry.getStart());
}
}
// If we got no dates, then no recurrences in the period so zap
if (dates.size() == 0) {
allResults.remove(entryResult);
// Remains sorted despite delete
return false;
}
// if some instances were updated
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
childNodeTypeQNames = new HashSet<QName>();
childNodeTypeQNames.add(CalendarModel.TYPE_UPDATED_EVENT);
List<ChildAssociationRef> updatedEventList = nodeService.getChildAssocs(entry.getNodeRef(), childNodeTypeQNames);
Map<String, Object> updatedDates = new HashMap<String, Object>();
for (ChildAssociationRef updatedEvent : updatedEventList) {
NodeRef nodeRef = updatedEvent.getChildRef();
Date updatedDate = (Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_EVENT_DATE);
Date newStart = (Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_START);
Date newEnd = (Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_END);
String newWhere = (String) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_WHERE);
String newWhat = (String) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_WHAT);
updatedDates.put(fmt.format(updatedDate), new Date[] { newStart, newEnd });
updatedDates.put(fmt.format(updatedDate).toString() + "where", newWhere);
updatedDates.put(fmt.format(updatedDate).toString() + "what", newWhat);
}
// first occurrence can be edited as separate event
Date liveEntry = dates.get(0);
// If first result only, alter title and finish
if (repeatingFirstOnly) {
entryResult.put(RESULT_TITLE, entry.getTitle() + " (Repeating)");
updateRepeating(entry, updatedDates, entryResult, duration, fmt, liveEntry);
// Date has been changed
return true;
} else {
// Otherwise generate one entry per extra date
for (int i = 1; i < dates.size(); i++) {
// Clone the properties
Map<String, Object> newResult = new HashMap<String, Object>(entryResult);
Date extra = dates.get(i);
updateRepeating(entry, updatedDates, newResult, duration, fmt, extra);
// Save as a new event
allResults.add(newResult);
}
updateRepeating(entry, updatedDates, entryResult, duration, fmt, liveEntry);
}
// New dates have been added
return true;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.
the class CalendarEntriesListGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
// Evil format needed for compatibility with old API...
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
// Decide on date ranges and repeating rules
Date fromDate = parseDate(req.getParameter("from"));
Date toDate = parseDate(req.getParameter("to"));
boolean resortNeeded = false;
boolean repeatingFirstOnly = true;
String repeatingEvents = req.getParameter("repeating");
if (repeatingEvents != null) {
if ("first".equals(repeatingEvents)) {
repeatingFirstOnly = true;
} else if ("all".equals(repeatingEvents)) {
repeatingFirstOnly = false;
resortNeeded = true;
}
}
// Get the entries for the list
PagingRequest paging = buildPagingRequest(req);
PagingResults<CalendarEntry> entries = calendarService.listCalendarEntries(new String[] { site.getShortName() }, fromDate, toDate, paging);
// For each one in our page, grab details of any ignored instances
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
for (CalendarEntry entry : entries.getPage()) {
Map<String, Object> result = new HashMap<String, Object>();
result.put(RESULT_EVENT, entry);
result.put(RESULT_NAME, entry.getSystemName());
result.put(RESULT_TITLE, entry.getTitle());
boolean isAllDay = CalendarEntryDTO.isAllDay(entry);
boolean removeTimezone = isAllDay && !entry.isOutlook();
result.put(RESULT_START, removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
result.put(RESULT_END, removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
if (isAllDay) {
long dayLong = 86400000;
Date newDay = new Date(entry.getEnd().getTime() + dayLong);
result.put("allDayEnd", newDay);
}
String legacyDateFormat = "M/d/yyyy";
String legacyTimeFormat = "HH:mm";
result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("fromDate", entry.getStart());
result.put("tags", entry.getTags());
List<ChildAssociationRef> ignores = nodeService.getChildAssocs(entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT, ContentModel.ASSOC_CONTAINS, true);
List<String> ignoreEvents = new ArrayList<String>();
List<Date> ignoreEventDates = new ArrayList<Date>();
for (ChildAssociationRef ref : ignores) {
Date date = (Date) nodeService.getProperty(ref.getChildRef(), CalendarModel.PROP_IGNORE_EVENT_DATE);
if (date != null) {
ignoreEventDates.add(date);
ignoreEvents.add(formatter.format(date));
}
}
result.put("ignoreEvents", ignoreEvents);
result.put("ignoreEventDates", ignoreEventDates);
// For repeating events, push forward if needed
boolean orderChanged = handleRecurring(entry, result, results, fromDate, toDate, repeatingFirstOnly);
if (orderChanged) {
resortNeeded = true;
}
// All done with this one
results.add(result);
}
// If they asked for repeating events to be expanded, then do so
if (resortNeeded) {
Collections.sort(results, getEventDetailsSorter());
}
// All done
Map<String, Object> model = new HashMap<String, Object>();
model.put("events", results);
model.put("siteId", site.getShortName());
model.put("site", site);
return model;
}
Aggregations