Line-endings only

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14122 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2009-04-29 14:26:46 +00:00
parent d0d8f02f2b
commit d4e4aeeaa3
13 changed files with 2334 additions and 2334 deletions

View File

@@ -1,38 +1,38 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities; package org.alfresco.repo.activities;
public interface ActivityType public interface ActivityType
{ {
// pre-defined alfresco activity types // pre-defined alfresco activity types
// generic fallback (if specific template is missing) // generic fallback (if specific template is missing)
public final String GENERIC_FALLBACK = "org.alfresco.generic"; public final String GENERIC_FALLBACK = "org.alfresco.generic";
// site membership // site membership
public final String SITE_USER_JOINED = "org.alfresco.site.user-joined"; public final String SITE_USER_JOINED = "org.alfresco.site.user-joined";
public final String SITE_USER_REMOVED = "org.alfresco.site.user-left"; public final String SITE_USER_REMOVED = "org.alfresco.site.user-left";
public final String SITE_USER_ROLE_UPDATE = "org.alfresco.site.user-role-changed"; public final String SITE_USER_ROLE_UPDATE = "org.alfresco.site.user-role-changed";
} }

View File

@@ -1,39 +1,39 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed; package org.alfresco.repo.activities.feed;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Interface for feed grid job * Interface for feed grid job
*/ */
public interface FeedGridJob public interface FeedGridJob
{ {
public void setArgument(JobSettings arg); public void setArgument(JobSettings arg);
public JobSettings getArgument(); public JobSettings getArgument();
public Serializable execute() throws Exception; public Serializable execute() throws Exception;
} }

View File

@@ -1,70 +1,70 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed; package org.alfresco.repo.activities.feed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
* Responsible for splitting the feed task into feed jobs (to be executed locally or on a grid) * Responsible for splitting the feed task into feed jobs (to be executed locally or on a grid)
*/ */
public class FeedTaskSplit public class FeedTaskSplit
{ {
private static Log logger = LogFactory.getLog(FeedTaskSplit.class); private static Log logger = LogFactory.getLog(FeedTaskSplit.class);
public Collection<JobSettings> split(int gridSize, JobSettings splitSettings) public Collection<JobSettings> split(int gridSize, JobSettings splitSettings)
{ {
long maxSequence = splitSettings.getMaxSeq(); long maxSequence = splitSettings.getMaxSeq();
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("split: start - gridSize = " + gridSize + ", maxSequence = " + maxSequence); logger.debug("split: start - gridSize = " + gridSize + ", maxSequence = " + maxSequence);
} }
long minSequence = maxSequence - splitSettings.getMaxItemsPerCycle() + 1; long minSequence = maxSequence - splitSettings.getMaxItemsPerCycle() + 1;
splitSettings.setMinSeq((minSequence >= 0L ? minSequence : 0L)); splitSettings.setMinSeq((minSequence >= 0L ? minSequence : 0L));
List<JobSettings> jobs = new ArrayList<JobSettings>(gridSize); List<JobSettings> jobs = new ArrayList<JobSettings>(gridSize);
int maxNodeHash = splitSettings.getJobTaskNode(); int maxNodeHash = splitSettings.getJobTaskNode();
// note: gridSize may change between runs, hence use maximum node hash/bucket for this cycle // note: gridSize may change between runs, hence use maximum node hash/bucket for this cycle
for (int n = 1; n <= maxNodeHash; n++) for (int n = 1; n <= maxNodeHash; n++)
{ {
// every job gets its own copy of the jobSettings (with different nodeHash) as an argument. // every job gets its own copy of the jobSettings (with different nodeHash) as an argument.
JobSettings jobSettings = splitSettings.clone(); JobSettings jobSettings = splitSettings.clone();
jobSettings.setJobTaskNode(n); jobSettings.setJobTaskNode(n);
jobs.add(jobSettings); jobs.add(jobSettings);
} }
return jobs; return jobs;
} }
} }

View File

@@ -1,100 +1,100 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed; package org.alfresco.repo.activities.feed;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Job settings passed from grid task to grid job * Job settings passed from grid task to grid job
*/ */
public class JobSettings implements Serializable public class JobSettings implements Serializable
{ {
public static final long serialVersionUID = -3896042917378679686L; public static final long serialVersionUID = -3896042917378679686L;
private int jobTaskNode; private int jobTaskNode;
private long maxSeq; private long maxSeq;
private long minSeq; private long minSeq;
private RepoCtx ctx; private RepoCtx ctx;
private int maxItemsPerCycle; private int maxItemsPerCycle;
public int getJobTaskNode() public int getJobTaskNode()
{ {
return jobTaskNode; return jobTaskNode;
} }
public void setJobTaskNode(int jobTaskNode) public void setJobTaskNode(int jobTaskNode)
{ {
this.jobTaskNode = jobTaskNode; this.jobTaskNode = jobTaskNode;
} }
public long getMaxSeq() public long getMaxSeq()
{ {
return maxSeq; return maxSeq;
} }
public void setMaxSeq(long maxSeq) public void setMaxSeq(long maxSeq)
{ {
this.maxSeq = maxSeq; this.maxSeq = maxSeq;
} }
public long getMinSeq() public long getMinSeq()
{ {
return minSeq; return minSeq;
} }
public void setMinSeq(long minSeq) public void setMinSeq(long minSeq)
{ {
this.minSeq = minSeq; this.minSeq = minSeq;
} }
public RepoCtx getWebScriptsCtx() { public RepoCtx getWebScriptsCtx() {
return ctx; return ctx;
} }
public void setWebScriptsCtx(RepoCtx ctx) { public void setWebScriptsCtx(RepoCtx ctx) {
this.ctx = ctx; this.ctx = ctx;
} }
public int getMaxItemsPerCycle() public int getMaxItemsPerCycle()
{ {
return maxItemsPerCycle; return maxItemsPerCycle;
} }
public void setMaxItemsPerCycle(int maxItemsPerCycle) public void setMaxItemsPerCycle(int maxItemsPerCycle)
{ {
this.maxItemsPerCycle = maxItemsPerCycle; this.maxItemsPerCycle = maxItemsPerCycle;
} }
public JobSettings clone() public JobSettings clone()
{ {
JobSettings js = new JobSettings(); JobSettings js = new JobSettings();
js.setMaxItemsPerCycle(this.maxItemsPerCycle); js.setMaxItemsPerCycle(this.maxItemsPerCycle);
js.setMaxSeq(this.maxSeq); js.setMaxSeq(this.maxSeq);
js.setMinSeq(this.minSeq); js.setMinSeq(this.minSeq);
js.setJobTaskNode(this.jobTaskNode); js.setJobTaskNode(this.jobTaskNode);
js.setWebScriptsCtx(this.ctx); // note: shallow copy js.setWebScriptsCtx(this.ctx); // note: shallow copy
return js; return js;
} }
} }

View File

@@ -1,69 +1,69 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed; package org.alfresco.repo.activities.feed;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Repository context passed from grid task to grid job * Repository context passed from grid task to grid job
*/ */
public class RepoCtx implements Serializable public class RepoCtx implements Serializable
{ {
private String repoEndPoint; // http://hostname:port/webapp (eg. http://localhost:8080/alfresco) private String repoEndPoint; // http://hostname:port/webapp (eg. http://localhost:8080/alfresco)
private boolean userNamesAreCaseSensitive = false; private boolean userNamesAreCaseSensitive = false;
private String ticket; private String ticket;
public static final long serialVersionUID = -3896042917378679686L; public static final long serialVersionUID = -3896042917378679686L;
public RepoCtx(String repoEndPoint) public RepoCtx(String repoEndPoint)
{ {
this.repoEndPoint = repoEndPoint.endsWith("/") ? repoEndPoint.substring(0, repoEndPoint.length()-1) : repoEndPoint; this.repoEndPoint = repoEndPoint.endsWith("/") ? repoEndPoint.substring(0, repoEndPoint.length()-1) : repoEndPoint;
} }
public String getRepoEndPoint() { public String getRepoEndPoint() {
return repoEndPoint; return repoEndPoint;
} }
public String getTicket() public String getTicket()
{ {
return ticket; return ticket;
} }
public void setTicket(String ticket) public void setTicket(String ticket)
{ {
this.ticket = ticket; this.ticket = ticket;
} }
public boolean isUserNamesAreCaseSensitive() public boolean isUserNamesAreCaseSensitive()
{ {
return userNamesAreCaseSensitive; return userNamesAreCaseSensitive;
} }
public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive) public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive)
{ {
this.userNamesAreCaseSensitive = userNamesAreCaseSensitive; this.userNamesAreCaseSensitive = userNamesAreCaseSensitive;
} }
} }

View File

@@ -1,80 +1,80 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed.local; package org.alfresco.repo.activities.feed.local;
import java.io.Serializable; import java.io.Serializable;
import org.alfresco.repo.activities.feed.FeedGridJob; import org.alfresco.repo.activities.feed.FeedGridJob;
import org.alfresco.repo.activities.feed.FeedTaskProcessor; import org.alfresco.repo.activities.feed.FeedTaskProcessor;
import org.alfresco.repo.activities.feed.JobSettings; import org.alfresco.repo.activities.feed.JobSettings;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
* Implementation to execute local (ie. not grid) feed job * Implementation to execute local (ie. not grid) feed job
*/ */
public class LocalFeedGridJob implements FeedGridJob public class LocalFeedGridJob implements FeedGridJob
{ {
private static final Log logger = LogFactory.getLog(LocalFeedGridJob.class); private static final Log logger = LogFactory.getLog(LocalFeedGridJob.class);
private JobSettings arg; private JobSettings arg;
private FeedTaskProcessor feedTaskProcessor; private FeedTaskProcessor feedTaskProcessor;
public void setFeedTaskProcessor(FeedTaskProcessor feedTaskProcessor) public void setFeedTaskProcessor(FeedTaskProcessor feedTaskProcessor)
{ {
this.feedTaskProcessor = feedTaskProcessor; this.feedTaskProcessor = feedTaskProcessor;
} }
public Serializable execute() throws Exception public Serializable execute() throws Exception
{ {
JobSettings js = getArgument(); JobSettings js = getArgument();
if (logger.isDebugEnabled()) { logger.debug(">>> Execute: nodehash '" + js.getJobTaskNode() + "' from seq '" + js.getMinSeq() + "' to seq '" + js.getMaxSeq() + "' on this node"); } if (logger.isDebugEnabled()) { logger.debug(">>> Execute: nodehash '" + js.getJobTaskNode() + "' from seq '" + js.getMinSeq() + "' to seq '" + js.getMaxSeq() + "' on this node"); }
try try
{ {
feedTaskProcessor.process(js.getJobTaskNode(), js.getMinSeq(), js.getMaxSeq(), js.getWebScriptsCtx()); feedTaskProcessor.process(js.getJobTaskNode(), js.getMinSeq(), js.getMaxSeq(), js.getWebScriptsCtx());
} }
catch (Exception e) catch (Exception e)
{ {
logger.error(e); logger.error(e);
throw new Exception(e.getMessage(), e.getCause()); throw new Exception(e.getMessage(), e.getCause());
} }
// This job does not return any result. // This job does not return any result.
return null; return null;
} }
public void setArgument(JobSettings arg) public void setArgument(JobSettings arg)
{ {
this.arg = arg; this.arg = arg;
} }
public JobSettings getArgument() public JobSettings getArgument()
{ {
return this.arg; return this.arg;
} }
} }

View File

@@ -1,107 +1,107 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed.local; package org.alfresco.repo.activities.feed.local;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import org.alfresco.repo.activities.feed.FeedTaskProcessor; import org.alfresco.repo.activities.feed.FeedTaskProcessor;
import org.alfresco.repo.domain.activities.ActivityFeedDAO; import org.alfresco.repo.domain.activities.ActivityFeedDAO;
import org.alfresco.repo.domain.activities.ActivityFeedEntity; import org.alfresco.repo.domain.activities.ActivityFeedEntity;
import org.alfresco.repo.domain.activities.ActivityPostDAO; import org.alfresco.repo.domain.activities.ActivityPostDAO;
import org.alfresco.repo.domain.activities.ActivityPostEntity; import org.alfresco.repo.domain.activities.ActivityPostEntity;
import org.alfresco.repo.domain.activities.FeedControlDAO; import org.alfresco.repo.domain.activities.FeedControlDAO;
import org.alfresco.repo.domain.activities.FeedControlEntity; import org.alfresco.repo.domain.activities.FeedControlEntity;
import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClient;
/** /**
* The local (ie. not grid) feed task processor is responsible for processing the individual feed job * The local (ie. not grid) feed task processor is responsible for processing the individual feed job
*/ */
public class LocalFeedTaskProcessor extends FeedTaskProcessor public class LocalFeedTaskProcessor extends FeedTaskProcessor
{ {
private ActivityPostDAO postDAO; private ActivityPostDAO postDAO;
private ActivityFeedDAO feedDAO; private ActivityFeedDAO feedDAO;
private FeedControlDAO feedControlDAO; private FeedControlDAO feedControlDAO;
// used to start/end/commit transaction // used to start/end/commit transaction
// note: currently assumes that all dao services are configured with this mapper / data source // note: currently assumes that all dao services are configured with this mapper / data source
private SqlMapClient sqlMapper; private SqlMapClient sqlMapper;
public void setPostDAO(ActivityPostDAO postDAO) public void setPostDAO(ActivityPostDAO postDAO)
{ {
this.postDAO = postDAO; this.postDAO = postDAO;
} }
public void setFeedDAO(ActivityFeedDAO feedDAO) public void setFeedDAO(ActivityFeedDAO feedDAO)
{ {
this.feedDAO = feedDAO; this.feedDAO = feedDAO;
} }
public void setFeedControlDAO(FeedControlDAO feedControlDAO) public void setFeedControlDAO(FeedControlDAO feedControlDAO)
{ {
this.feedControlDAO = feedControlDAO; this.feedControlDAO = feedControlDAO;
} }
public void setSqlMapClient(SqlMapClient sqlMapper) public void setSqlMapClient(SqlMapClient sqlMapper)
{ {
this.sqlMapper = sqlMapper; this.sqlMapper = sqlMapper;
} }
public void startTransaction() throws SQLException public void startTransaction() throws SQLException
{ {
sqlMapper.startTransaction(); sqlMapper.startTransaction();
} }
public void commitTransaction() throws SQLException public void commitTransaction() throws SQLException
{ {
sqlMapper.commitTransaction(); sqlMapper.commitTransaction();
} }
public void endTransaction() throws SQLException public void endTransaction() throws SQLException
{ {
sqlMapper.endTransaction(); sqlMapper.endTransaction();
} }
public List<ActivityPostEntity> selectPosts(ActivityPostEntity selector) throws SQLException public List<ActivityPostEntity> selectPosts(ActivityPostEntity selector) throws SQLException
{ {
return postDAO.selectPosts(selector); return postDAO.selectPosts(selector);
} }
public long insertFeedEntry(ActivityFeedEntity feed) throws SQLException public long insertFeedEntry(ActivityFeedEntity feed) throws SQLException
{ {
return feedDAO.insertFeedEntry(feed); return feedDAO.insertFeedEntry(feed);
} }
public int updatePostStatus(long id, ActivityPostEntity.STATUS status) throws SQLException public int updatePostStatus(long id, ActivityPostEntity.STATUS status) throws SQLException
{ {
return postDAO.updatePostStatus(id, status); return postDAO.updatePostStatus(id, status);
} }
public List<FeedControlEntity> selectUserFeedControls(String userId) throws SQLException public List<FeedControlEntity> selectUserFeedControls(String userId) throws SQLException
{ {
return feedControlDAO.selectFeedControls(userId); return feedControlDAO.selectFeedControls(userId);
} }
} }

View File

@@ -1,76 +1,76 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.feed.local; package org.alfresco.repo.activities.feed.local;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.alfresco.repo.activities.feed.FeedGridJob; import org.alfresco.repo.activities.feed.FeedGridJob;
import org.alfresco.repo.activities.feed.FeedTaskProcessor; import org.alfresco.repo.activities.feed.FeedTaskProcessor;
import org.alfresco.repo.activities.feed.FeedTaskSplit; import org.alfresco.repo.activities.feed.FeedTaskSplit;
import org.alfresco.repo.activities.feed.JobSettings; import org.alfresco.repo.activities.feed.JobSettings;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
* The local feed task splitter is responsible for splitting the feed task into feed jobs * The local feed task splitter is responsible for splitting the feed task into feed jobs
*/ */
public class LocalFeedTaskSplitter public class LocalFeedTaskSplitter
{ {
private static final Log logger = LogFactory.getLog(LocalFeedTaskSplitter.class); private static final Log logger = LogFactory.getLog(LocalFeedTaskSplitter.class);
private FeedTaskProcessor feedTaskProcessor; private FeedTaskProcessor feedTaskProcessor;
public void setFeedTaskProcessor(FeedTaskProcessor feedTaskProcessor) public void setFeedTaskProcessor(FeedTaskProcessor feedTaskProcessor)
{ {
this.feedTaskProcessor = feedTaskProcessor; this.feedTaskProcessor = feedTaskProcessor;
} }
public Collection<FeedGridJob> split(int gridSize, Object o) throws Exception public Collection<FeedGridJob> split(int gridSize, Object o) throws Exception
{ {
try try
{ {
FeedTaskSplit feedSplitter = new FeedTaskSplit(); FeedTaskSplit feedSplitter = new FeedTaskSplit();
Collection<JobSettings> jobs = feedSplitter.split(gridSize, (JobSettings)o); Collection<JobSettings> jobs = feedSplitter.split(gridSize, (JobSettings)o);
List<FeedGridJob> gridJobs = new ArrayList<FeedGridJob>(jobs.size()); List<FeedGridJob> gridJobs = new ArrayList<FeedGridJob>(jobs.size());
for (JobSettings job : jobs) for (JobSettings job : jobs)
{ {
LocalFeedGridJob gridJob = new LocalFeedGridJob(); LocalFeedGridJob gridJob = new LocalFeedGridJob();
gridJob.setFeedTaskProcessor(feedTaskProcessor); gridJob.setFeedTaskProcessor(feedTaskProcessor);
gridJob.setArgument(job); gridJob.setArgument(job);
gridJobs.add(gridJob); gridJobs.add(gridJob);
} }
return gridJobs; return gridJobs;
//return (Collection<FeedGridJob>)feedSplitter.split(gridSize, (JobSettings)o, new LocalFeedGridJob()); //return (Collection<FeedGridJob>)feedSplitter.split(gridSize, (JobSettings)o, new LocalFeedGridJob());
} }
catch (Exception e) catch (Exception e)
{ {
logger.equals(e); logger.equals(e);
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
} }
} }

View File

@@ -1,351 +1,351 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.post.lookup; package org.alfresco.repo.activities.post.lookup;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.activities.ActivityPostDAO; import org.alfresco.repo.domain.activities.ActivityPostDAO;
import org.alfresco.repo.domain.activities.ActivityPostEntity; import org.alfresco.repo.domain.activities.ActivityPostEntity;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.alfresco.util.VmShutdownListener; import org.alfresco.util.VmShutdownListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener; import org.json.JSONTokener;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
/** /**
* The post lookup component is responsible for updating posts that require a secondary lookup (to get additional activity data) * The post lookup component is responsible for updating posts that require a secondary lookup (to get additional activity data)
*/ */
public class PostLookup public class PostLookup
{ {
private static Log logger = LogFactory.getLog(PostLookup.class); private static Log logger = LogFactory.getLog(PostLookup.class);
private static VmShutdownListener vmShutdownListener = new VmShutdownListener(PostLookup.class.getName()); private static VmShutdownListener vmShutdownListener = new VmShutdownListener(PostLookup.class.getName());
private ActivityPostDAO postDAO; private ActivityPostDAO postDAO;
private NodeService nodeService; private NodeService nodeService;
private PermissionService permissionService; private PermissionService permissionService;
private TransactionService transactionService; private TransactionService transactionService;
private PersonService personService; private PersonService personService;
private TenantService tenantService; private TenantService tenantService;
public void setPostDAO(ActivityPostDAO postDAO) public void setPostDAO(ActivityPostDAO postDAO)
{ {
this.postDAO = postDAO; this.postDAO = postDAO;
} }
public void setNodeService(NodeService nodeService) public void setNodeService(NodeService nodeService)
{ {
this.nodeService = nodeService; this.nodeService = nodeService;
} }
public void setPermissionService(PermissionService permissionService) public void setPermissionService(PermissionService permissionService)
{ {
this.permissionService = permissionService; this.permissionService = permissionService;
} }
public void setTransactionService(TransactionService transactionService) public void setTransactionService(TransactionService transactionService)
{ {
this.transactionService = transactionService; this.transactionService = transactionService;
} }
public void setPersonService(PersonService personService) public void setPersonService(PersonService personService)
{ {
this.personService = personService; this.personService = personService;
} }
public void setTenantService(TenantService tenantService) public void setTenantService(TenantService tenantService)
{ {
this.tenantService = tenantService; this.tenantService = tenantService;
} }
/** /**
* Perform basic checks to ensure that the necessary dependencies were injected. * Perform basic checks to ensure that the necessary dependencies were injected.
*/ */
private void checkProperties() private void checkProperties()
{ {
PropertyCheck.mandatory(this, "postDAO", postDAO); PropertyCheck.mandatory(this, "postDAO", postDAO);
PropertyCheck.mandatory(this, "nodeService", nodeService); PropertyCheck.mandatory(this, "nodeService", nodeService);
PropertyCheck.mandatory(this, "permissionService", permissionService); PropertyCheck.mandatory(this, "permissionService", permissionService);
PropertyCheck.mandatory(this, "transactionService", transactionService); PropertyCheck.mandatory(this, "transactionService", transactionService);
PropertyCheck.mandatory(this, "personService", personService); PropertyCheck.mandatory(this, "personService", personService);
PropertyCheck.mandatory(this, "tenantService", tenantService); PropertyCheck.mandatory(this, "tenantService", tenantService);
} }
public void execute() throws JobExecutionException public void execute() throws JobExecutionException
{ {
checkProperties(); checkProperties();
try try
{ {
ActivityPostEntity params = new ActivityPostEntity(); ActivityPostEntity params = new ActivityPostEntity();
params.setStatus(ActivityPostEntity.STATUS.PENDING.toString()); params.setStatus(ActivityPostEntity.STATUS.PENDING.toString());
List<ActivityPostEntity> activityPosts = postDAO.selectPosts(params); List<ActivityPostEntity> activityPosts = postDAO.selectPosts(params);
if (activityPosts.size() > 0) if (activityPosts.size() > 0)
{ {
logger.info("Update: " + activityPosts.size() + " activity posts"); logger.info("Update: " + activityPosts.size() + " activity posts");
} }
for (final ActivityPostEntity activityPost : activityPosts) for (final ActivityPostEntity activityPost : activityPosts)
{ {
try try
{ {
postDAO.startTransaction(); postDAO.startTransaction();
final JSONObject jo = new JSONObject(new JSONTokener(activityPost.getActivityData())); final JSONObject jo = new JSONObject(new JSONTokener(activityPost.getActivityData()));
final String postUserId = activityPost.getUserId(); final String postUserId = activityPost.getUserId();
// MT share // MT share
String tenantDomain = tenantService.getUserDomain(postUserId); String tenantDomain = tenantService.getUserDomain(postUserId);
AuthenticationUtil.runAs(new RunAsWork<Object>() AuthenticationUtil.runAs(new RunAsWork<Object>()
{ {
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
if (! jo.isNull("nodeRef")) if (! jo.isNull("nodeRef"))
{ {
String nodeRefStr = jo.getString("nodeRef"); String nodeRefStr = jo.getString("nodeRef");
NodeRef nodeRef = new NodeRef(nodeRefStr); NodeRef nodeRef = new NodeRef(nodeRefStr);
// lookup additional node data // lookup additional node data
JSONObject activityData = lookupNode(nodeRef, postUserId, jo); JSONObject activityData = lookupNode(nodeRef, postUserId, jo);
activityPost.setActivityData(activityData.toString()); activityPost.setActivityData(activityData.toString());
} }
else else
{ {
// lookup additional person data // lookup additional person data
Pair<String, String> firstLastName = lookupPerson(postUserId); Pair<String, String> firstLastName = lookupPerson(postUserId);
if (firstLastName != null) if (firstLastName != null)
{ {
jo.put("firstName", firstLastName.getFirst()); jo.put("firstName", firstLastName.getFirst());
jo.put("lastName", firstLastName.getSecond()); jo.put("lastName", firstLastName.getSecond());
activityPost.setActivityData(jo.toString()); activityPost.setActivityData(jo.toString());
} }
} }
activityPost.setLastModified(new Date()); activityPost.setLastModified(new Date());
postDAO.updatePost(activityPost.getId(), activityPost.getSiteNetwork(), activityPost.getActivityData(), ActivityPostEntity.STATUS.POSTED); postDAO.updatePost(activityPost.getId(), activityPost.getSiteNetwork(), activityPost.getActivityData(), ActivityPostEntity.STATUS.POSTED);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
activityPost.setStatus(ActivityPostEntity.STATUS.POSTED.toString()); // for debug output activityPost.setStatus(ActivityPostEntity.STATUS.POSTED.toString()); // for debug output
logger.debug("Updated: " + activityPost); logger.debug("Updated: " + activityPost);
} }
return null; return null;
} }
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain)); }, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
postDAO.commitTransaction(); postDAO.commitTransaction();
} }
catch (JSONException e) catch (JSONException e)
{ {
// log error, but consume exception (skip this post) // log error, but consume exception (skip this post)
logger.error("Skipping activity post " + activityPost.getId() + ": " + e); logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR); postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
postDAO.commitTransaction(); postDAO.commitTransaction();
} }
catch (SQLException e) catch (SQLException e)
{ {
logger.error("Exception during update of post", e); logger.error("Exception during update of post", e);
throw new JobExecutionException(e); throw new JobExecutionException(e);
} }
finally finally
{ {
postDAO.endTransaction(); postDAO.endTransaction();
} }
} }
} }
catch (SQLException e) catch (SQLException e)
{ {
logger.error("Exception during select of posts", e); logger.error("Exception during select of posts", e);
throw new JobExecutionException(e); throw new JobExecutionException(e);
} }
catch (Throwable e) catch (Throwable e)
{ {
// If the VM is shutting down, then ignore // If the VM is shutting down, then ignore
if (vmShutdownListener.isVmShuttingDown()) if (vmShutdownListener.isVmShuttingDown())
{ {
// Ignore // Ignore
} }
else else
{ {
logger.error("Exception during update of posts", e); logger.error("Exception during update of posts", e);
} }
} }
} }
private Pair<String, String> lookupPerson(final String postUserId) throws JSONException private Pair<String, String> lookupPerson(final String postUserId) throws JSONException
{ {
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
// wrap to make the request in a transaction // wrap to make the request in a transaction
RetryingTransactionCallback<Pair<String, String>> lookup = new RetryingTransactionCallback<Pair<String, String>>() RetryingTransactionCallback<Pair<String, String>> lookup = new RetryingTransactionCallback<Pair<String, String>>()
{ {
public Pair<String, String> execute() throws Throwable public Pair<String, String> execute() throws Throwable
{ {
String firstName = ""; String firstName = "";
String lastName = ""; String lastName = "";
if (personService.personExists(postUserId)) if (personService.personExists(postUserId))
{ {
NodeRef personRef = personService.getPerson(postUserId); NodeRef personRef = personService.getPerson(postUserId);
firstName = (String)nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME); firstName = (String)nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
lastName = (String)nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME); lastName = (String)nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
return new Pair<String, String>(firstName, lastName); return new Pair<String, String>(firstName, lastName);
} }
return null; return null;
} }
}; };
// execute in txn // execute in txn
return txnHelper.doInTransaction(lookup, true); return txnHelper.doInTransaction(lookup, true);
} }
private JSONObject lookupNode(final NodeRef nodeRef, final String postUserId, final JSONObject jo) throws JSONException private JSONObject lookupNode(final NodeRef nodeRef, final String postUserId, final JSONObject jo) throws JSONException
{ {
return AuthenticationUtil.runAs(new RunAsWork<JSONObject>() return AuthenticationUtil.runAs(new RunAsWork<JSONObject>()
{ {
public JSONObject doWork() throws Exception public JSONObject doWork() throws Exception
{ {
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
// wrap to make the request in a transaction // wrap to make the request in a transaction
RetryingTransactionCallback<JSONObject> lookup = new RetryingTransactionCallback<JSONObject>() RetryingTransactionCallback<JSONObject> lookup = new RetryingTransactionCallback<JSONObject>()
{ {
public JSONObject execute() throws Throwable public JSONObject execute() throws Throwable
{ {
String name = ""; String name = "";
if (! jo.isNull("name")) if (! jo.isNull("name"))
{ {
name = jo.getString("name"); name = jo.getString("name");
} }
NodeRef parentNodeRef = null; NodeRef parentNodeRef = null;
if (! jo.isNull("parentNodeRef")) if (! jo.isNull("parentNodeRef"))
{ {
parentNodeRef = new NodeRef(jo.getString("parentNodeRef")); parentNodeRef = new NodeRef(jo.getString("parentNodeRef"));
} }
String typeQName = ""; String typeQName = "";
if (! jo.isNull("typeQName")) if (! jo.isNull("typeQName"))
{ {
typeQName = jo.getString("typeQName"); typeQName = jo.getString("typeQName");
} }
String displayPath = ""; String displayPath = "";
Path path = null; Path path = null;
String firstName = ""; String firstName = "";
String lastName = ""; String lastName = "";
if (personService.personExists(postUserId)) if (personService.personExists(postUserId))
{ {
// lookup firstname, lastname // lookup firstname, lastname
NodeRef personRef = personService.getPerson(postUserId); NodeRef personRef = personService.getPerson(postUserId);
firstName = (String)nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME); firstName = (String)nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
lastName = (String)nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME); lastName = (String)nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
} }
if ((nodeRef != null) && (nodeService.exists(nodeRef))) if ((nodeRef != null) && (nodeService.exists(nodeRef)))
{ {
if (name.length() == 0) if (name.length() == 0)
{ {
// lookup node name // lookup node name
name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
} }
if (typeQName.length() == 0) if (typeQName.length() == 0)
{ {
// lookup type // lookup type
typeQName = nodeService.getType(nodeRef).toPrefixString(); // TODO: missing the prefix ? typeQName = nodeService.getType(nodeRef).toPrefixString(); // TODO: missing the prefix ?
} }
if (parentNodeRef == null) if (parentNodeRef == null)
{ {
// lookup parent node // lookup parent node
parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
} }
} }
if ((parentNodeRef != null) && (nodeService.exists(parentNodeRef))) if ((parentNodeRef != null) && (nodeService.exists(parentNodeRef)))
{ {
// parent node exists, lookup parent node path // parent node exists, lookup parent node path
path = nodeService.getPath(parentNodeRef); path = nodeService.getPath(parentNodeRef);
} }
if (path != null) if (path != null)
{ {
// lookup display path // lookup display path
displayPath = path.toDisplayPath(nodeService, permissionService); displayPath = path.toDisplayPath(nodeService, permissionService);
// note: for now, also tack on the node name // note: for now, also tack on the node name
displayPath += "/" + name; displayPath += "/" + name;
} }
// merge with existing activity data // merge with existing activity data
jo.put("name", name); jo.put("name", name);
jo.put("nodeRef", nodeRef.toString()); jo.put("nodeRef", nodeRef.toString());
jo.put("typeQName", typeQName); jo.put("typeQName", typeQName);
jo.put("parentNodeRef", (parentNodeRef != null ? parentNodeRef.toString() : null)); jo.put("parentNodeRef", (parentNodeRef != null ? parentNodeRef.toString() : null));
jo.put("displayPath", displayPath); jo.put("displayPath", displayPath);
jo.put("firstName", firstName); jo.put("firstName", firstName);
jo.put("lastName", lastName); jo.put("lastName", lastName);
return jo; return jo;
} }
}; };
// execute in txn // execute in txn
return txnHelper.doInTransaction(lookup, true); return txnHelper.doInTransaction(lookup, true);
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
} }

View File

@@ -1,157 +1,157 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.activities.script; package org.alfresco.repo.activities.script;
import java.util.List; import java.util.List;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.service.cmr.activities.ActivityService; import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.service.cmr.activities.FeedControl; import org.alfresco.service.cmr.activities.FeedControl;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
/** /**
* Scripted Activity Service for posting activities. * Scripted Activity Service for posting activities.
*/ */
public final class Activity extends BaseScopableProcessorExtension public final class Activity extends BaseScopableProcessorExtension
{ {
private ActivityService activityService; private ActivityService activityService;
/** /**
* Set the activity service * Set the activity service
* *
* @param activityService the activity service * @param activityService the activity service
*/ */
public void setActivityService(ActivityService activityService) public void setActivityService(ActivityService activityService)
{ {
this.activityService = activityService; this.activityService = activityService;
} }
/* /*
* Post Activity * Post Activity
*/ */
/** /**
* Post a custom activity type * Post a custom activity type
* *
* @param activityType - required * @param activityType - required
* @param siteId - optional, if null will be stored as empty string * @param siteId - optional, if null will be stored as empty string
* @param appTool - optional, if null will be stored as empty string * @param appTool - optional, if null will be stored as empty string
* @param jsonActivityData - required * @param jsonActivityData - required
*/ */
public void postActivity(String activityType, String siteId, String appTool, String jsonActivityData) public void postActivity(String activityType, String siteId, String appTool, String jsonActivityData)
{ {
activityService.postActivity(activityType, siteId, appTool, jsonActivityData); activityService.postActivity(activityType, siteId, appTool, jsonActivityData);
} }
/** /**
* Post a pre-defined activity type - activity data will be looked-up asynchronously, including: * Post a pre-defined activity type - activity data will be looked-up asynchronously, including:
* *
* name * name
* displayPath * displayPath
* typeQName * typeQName
* firstName (of posting user) * firstName (of posting user)
* lastName (of posting user) * lastName (of posting user)
* *
* @param activityType - required * @param activityType - required
* @param siteId - optional, if null will be stored as empty string * @param siteId - optional, if null will be stored as empty string
* @param appTool - optional, if null will be stored as empty string * @param appTool - optional, if null will be stored as empty string
* @param nodeRef - required - do not use for deleted (or about to be deleted) nodeRef * @param nodeRef - required - do not use for deleted (or about to be deleted) nodeRef
*/ */
public void postActivity(String activityType, String siteId, String appTool, NodeRef nodeRef) public void postActivity(String activityType, String siteId, String appTool, NodeRef nodeRef)
{ {
activityService.postActivity(activityType, siteId, appTool, nodeRef); activityService.postActivity(activityType, siteId, appTool, nodeRef);
} }
/** /**
* Post a pre-defined activity type - eg. for checked-out nodeRef or renamed nodeRef * Post a pre-defined activity type - eg. for checked-out nodeRef or renamed nodeRef
* *
* @param activityType - required * @param activityType - required
* @param siteId - optional, if null will be stored as empty string * @param siteId - optional, if null will be stored as empty string
* @param appTool - optional, if null will be stored as empty string * @param appTool - optional, if null will be stored as empty string
* @param nodeRef - required - do not use deleted (or about to be deleted) nodeRef * @param nodeRef - required - do not use deleted (or about to be deleted) nodeRef
* @param beforeName - optional - name of node (eg. prior to name change) * @param beforeName - optional - name of node (eg. prior to name change)
*/ */
public void postActivity(String activityType, String siteId, String appTool, NodeRef nodeRef, String beforeName) public void postActivity(String activityType, String siteId, String appTool, NodeRef nodeRef, String beforeName)
{ {
activityService.postActivity(activityType, siteId, appTool, nodeRef, beforeName); activityService.postActivity(activityType, siteId, appTool, nodeRef, beforeName);
} }
/** /**
* Post a pre-defined activity type - eg. for deleted nodeRef * Post a pre-defined activity type - eg. for deleted nodeRef
* *
* @param activityType - required * @param activityType - required
* @param siteId - optional, if null will be stored as empty string * @param siteId - optional, if null will be stored as empty string
* @param appTool - optional, if null will be stored as empty string * @param appTool - optional, if null will be stored as empty string
* @param nodeRef - required - can be a deleted (or about to be deleted) nodeRef * @param nodeRef - required - can be a deleted (or about to be deleted) nodeRef
* @param name - optional - name of name * @param name - optional - name of name
* @param typeQName - optional - type of node * @param typeQName - optional - type of node
* @param parentNodeRef - required - used to lookup path/displayPath * @param parentNodeRef - required - used to lookup path/displayPath
*/ */
public void postActivity(String activityType, String siteId, String appTool, NodeRef nodeRef, String name, QName typeQName, NodeRef parentNodeRef) public void postActivity(String activityType, String siteId, String appTool, NodeRef nodeRef, String name, QName typeQName, NodeRef parentNodeRef)
{ {
activityService.postActivity(activityType, siteId, appTool, nodeRef, name, typeQName, parentNodeRef); activityService.postActivity(activityType, siteId, appTool, nodeRef, name, typeQName, parentNodeRef);
} }
/* /*
* Manage User Feed Controls * Manage User Feed Controls
*/ */
/** /**
* For current user, get feed controls * For current user, get feed controls
* *
* @return array of user feed controls * @return array of user feed controls
*/ */
public FeedControl[] getFeedControls() public FeedControl[] getFeedControls()
{ {
List<FeedControl> feedControls = activityService.getFeedControls(); List<FeedControl> feedControls = activityService.getFeedControls();
return (FeedControl[])feedControls.toArray(new FeedControl[feedControls.size()]); return (FeedControl[])feedControls.toArray(new FeedControl[feedControls.size()]);
} }
/** /**
* For current user, set feed control (opt-out) for a site or an appTool or a site/appTool combination * For current user, set feed control (opt-out) for a site or an appTool or a site/appTool combination
* *
* @param siteId - required (optional, if appToolId is supplied) * @param siteId - required (optional, if appToolId is supplied)
* @param appToolId - required (optional, if siteId is supplied) * @param appToolId - required (optional, if siteId is supplied)
*/ */
public void setFeedControl(String siteId, String appToolId) public void setFeedControl(String siteId, String appToolId)
{ {
activityService.setFeedControl(new FeedControl(siteId, appToolId)); activityService.setFeedControl(new FeedControl(siteId, appToolId));
} }
/** /**
* For current user, unset feed control * For current user, unset feed control
* *
* @param siteId - required (optional, if appToolId is supplied) * @param siteId - required (optional, if appToolId is supplied)
* @param appToolId - required (optional, if siteId is supplied) * @param appToolId - required (optional, if siteId is supplied)
*/ */
public void unsetFeedControl(String siteId, String appToolId) public void unsetFeedControl(String siteId, String appToolId)
{ {
activityService.unsetFeedControl(new FeedControl(siteId, appToolId)); activityService.unsetFeedControl(new FeedControl(siteId, appToolId));
} }
} }

View File

@@ -1,46 +1,46 @@
// called by ActivityServiceImplTest.java (test_JSAPI) // called by ActivityServiceImplTest.java (test_JSAPI)
var failure = "did not complete script"; var failure = "did not complete script";
// invalid // invalid
// activities.postActivity("my activity type", null, null, null); // activities.postActivity("my activity type", null, null, null);
// activities.postActivity(null, "my site", "my app tool", '{ 000 }'); // activities.postActivity(null, "my site", "my app tool", '{ 000 }');
// valid // valid
activities.postActivity("test activity type 4", null, null, '{ "item1" : 123 }'); activities.postActivity("test activity type 4", null, null, '{ "item1" : 123 }');
activities.postActivity("test activity type 5", "my site", null, '{ "item2" : 456 }'); activities.postActivity("test activity type 5", "my site", null, '{ "item2" : 456 }');
activities.postActivity("test activity type 6", "my site", "my app tool", '{ "item3" : 789 }'); activities.postActivity("test activity type 6", "my site", "my app tool", '{ "item3" : 789 }');
activities.postActivity("test activity type 7", "my site", "my app tool", '{ invalidJSON }'); activities.postActivity("test activity type 7", "my site", "my app tool", '{ invalidJSON }');
// user feed controls // user feed controls
var feedControls = activities.getFeedControls(); var feedControls = activities.getFeedControls();
test.assertEquals(0, feedControls.length); test.assertEquals(0, feedControls.length);
activities.setFeedControl("my site", "my app tool"); activities.setFeedControl("my site", "my app tool");
feedControls = activities.getFeedControls(); feedControls = activities.getFeedControls();
test.assertEquals(1, feedControls.length); test.assertEquals(1, feedControls.length);
activities.setFeedControl("my site", null); activities.setFeedControl("my site", null);
feedControls = activities.getFeedControls(); feedControls = activities.getFeedControls();
test.assertEquals(2, feedControls.length); test.assertEquals(2, feedControls.length);
activities.setFeedControl("", "my app tool"); activities.setFeedControl("", "my app tool");
feedControls = activities.getFeedControls(); feedControls = activities.getFeedControls();
test.assertEquals(3, feedControls.length); test.assertEquals(3, feedControls.length);
activities.unsetFeedControl("my site", "my app tool"); activities.unsetFeedControl("my site", "my app tool");
activities.unsetFeedControl("my site", ""); activities.unsetFeedControl("my site", "");
activities.unsetFeedControl(null, "my app tool"); activities.unsetFeedControl(null, "my app tool");
feedControls = activities.getFeedControls(); feedControls = activities.getFeedControls();
test.assertEquals(0, feedControls.length); test.assertEquals(0, feedControls.length);
failure = ""; failure = "";
// Return the failure message // Return the failure message
failure; failure;