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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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