mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged DEV to HEAD (5.0)
87808: ACE-2030: Remove more patches introduced for upgrade to V3.4 (pre-release) 87809: ACE-2030: Remove final 3.4 (pre-release) patches. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@87813 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,240 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.sql.Savepoint;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker;
|
||||
import org.alfresco.repo.domain.control.ControlDAO;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.domain.permissions.AclCrudDAO;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Fixes <a href=https://issues.alfresco.com/jira/browse/ALF-478>ALF-478</a>.
|
||||
* Checks all CRC values for <b>alf_authorities</b>.
|
||||
*
|
||||
* @author Andrew Hind
|
||||
* @since V3.3
|
||||
*/
|
||||
public class FixAuthoritiesCrcValuesPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.fixAuthoritiesCrcValues.result";
|
||||
private static final String MSG_REWRITTEN = "patch.fixAuthoritiesCrcValues.fixed";
|
||||
private static final String MSG_UNABLE_TO_CHANGE = "patch.fixAuthoritiesCrcValues.unableToChange";
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private PatchDAO patchDAO;
|
||||
private AclCrudDAO aclCrudDAO;
|
||||
private ControlDAO controlDAO;
|
||||
|
||||
public FixAuthoritiesCrcValuesPatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patchDAO finds incorrect authorities
|
||||
*/
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aclCrudDAO does the actual fixing
|
||||
*/
|
||||
public void setAclCrudDAO(AclCrudDAO aclCrudDAO)
|
||||
{
|
||||
this.aclCrudDAO = aclCrudDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param controlDAO used to create Savepoints
|
||||
*/
|
||||
public void setControlDAO(ControlDAO controlDAO)
|
||||
{
|
||||
this.controlDAO = controlDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
super.checkProperties();
|
||||
checkPropertyNotNull(patchDAO, "patchDAO");
|
||||
checkPropertyNotNull(aclCrudDAO, "aclCrudDAO");
|
||||
checkPropertyNotNull(controlDAO, "controlDAO");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
// initialise the helper
|
||||
FixAuthoritiesCrcValuesPatchHelper helper = new FixAuthoritiesCrcValuesPatchHelper();
|
||||
|
||||
try
|
||||
{
|
||||
String msg = helper.fixCrcValues();
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
finally
|
||||
{
|
||||
helper.closeWriter();
|
||||
}
|
||||
}
|
||||
|
||||
private class FixAuthoritiesCrcValuesPatchHelper
|
||||
{
|
||||
private File logFile;
|
||||
private FileChannel channel;
|
||||
|
||||
private FixAuthoritiesCrcValuesPatchHelper() throws IOException
|
||||
{
|
||||
// put the log file into a long life temp directory
|
||||
File tempDir = TempFileProvider.getLongLifeTempDir("patches");
|
||||
logFile = new File(tempDir, "FixAuthorityCrcValuesPatch.log");
|
||||
|
||||
// open the file for appending
|
||||
RandomAccessFile outputFile = new RandomAccessFile(logFile, "rw");
|
||||
channel = outputFile.getChannel();
|
||||
// move to the end of the file
|
||||
channel.position(channel.size());
|
||||
// add a newline and it's ready
|
||||
writeLine("").writeLine("");
|
||||
writeLine("FixAuthorityCrcValuesPatch executing on " + new Date());
|
||||
}
|
||||
|
||||
private FixAuthoritiesCrcValuesPatchHelper write(Object obj) throws IOException
|
||||
{
|
||||
channel.write(ByteBuffer.wrap(obj.toString().getBytes("UTF-8")));
|
||||
return this;
|
||||
}
|
||||
private FixAuthoritiesCrcValuesPatchHelper writeLine(Object obj) throws IOException
|
||||
{
|
||||
write(obj);
|
||||
write("\n");
|
||||
return this;
|
||||
}
|
||||
private void closeWriter()
|
||||
{
|
||||
try { channel.close(); } catch (Throwable e) {}
|
||||
}
|
||||
|
||||
public String fixCrcValues() throws Exception
|
||||
{
|
||||
List<String> mismatchedAuthorities = patchDAO.getAuthoritiesWithNonUtf8Crcs();
|
||||
// get the association types to check
|
||||
BatchProcessor<String> batchProcessor = new BatchProcessor<String>(
|
||||
"FixAuthorityCrcValuesPatch",
|
||||
transactionHelper,
|
||||
mismatchedAuthorities,
|
||||
2, 20,
|
||||
applicationEventPublisher,
|
||||
logger, 1000);
|
||||
|
||||
int updated = batchProcessor.process(new BatchProcessWorker<String>()
|
||||
{
|
||||
public String getIdentifier(String entry)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
// Authenticate as system
|
||||
String systemUsername = AuthenticationUtil.getSystemUserName();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(systemUsername);
|
||||
}
|
||||
|
||||
public void process(String authority) throws Throwable
|
||||
{
|
||||
// Persist
|
||||
Savepoint savepoint = controlDAO.createSavepoint("FixAuthorityCrcValuesPatch");
|
||||
try
|
||||
{
|
||||
aclCrudDAO.renameAuthority(authority, authority);
|
||||
controlDAO.releaseSavepoint(savepoint);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
controlDAO.rollbackToSavepoint(savepoint);
|
||||
|
||||
String msg = I18NUtil.getMessage(MSG_UNABLE_TO_CHANGE, authority, e.getMessage());
|
||||
// We just log this and add details to the message file
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(msg, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn(msg);
|
||||
}
|
||||
writeLine(msg);
|
||||
}
|
||||
// Record
|
||||
writeLine(I18NUtil.getMessage(MSG_REWRITTEN, authority));
|
||||
}
|
||||
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
}, true);
|
||||
|
||||
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, updated, logFile);
|
||||
return msg;
|
||||
}
|
||||
// Keeping this for reference. Actually, the query need only pull back the authority and crc
|
||||
// private List<String> findMismatchedCrcs() throws Exception
|
||||
// {
|
||||
// final List<Long> authorityIds = new ArrayList<Long>(1000);
|
||||
// HibernateCallback callback = new HibernateCallback()
|
||||
// {
|
||||
// public Object doInHibernate(Session session)
|
||||
// {
|
||||
// SQLQuery query = session
|
||||
// .createSQLQuery(
|
||||
// " SELECT " +
|
||||
// " au.id AS authority_id," +
|
||||
// " au.authority AS authority," +
|
||||
// " au.crc as crc" +
|
||||
// " FROM" +
|
||||
// " alf_authority au");
|
||||
// query.addScalar("authority_id", new LongType());
|
||||
// query.addScalar("authority", new StringType());
|
||||
// query.addScalar("crc", new LongType());
|
||||
// return query.scroll(ScrollMode.FORWARD_ONLY);
|
||||
// }
|
||||
// };
|
||||
}
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.security.sync.ChainingUserRegistrySynchronizer;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ibatis.session.ResultContext;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Migrate Chaining User Registry Synchronizer attributes (from 'alf_*attribute*' to 'alf_prop_*')
|
||||
*
|
||||
* @author janv
|
||||
* @since 3.4
|
||||
*/
|
||||
public class MigrateAttrChainingURSPatch extends AbstractPatch
|
||||
{
|
||||
private Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private static final String MSG_SUCCESS = "patch.migrateAttrChainingURS.result";
|
||||
|
||||
private AttributeService attributeService;
|
||||
private PatchDAO patchDAO;
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
ChainingURSResultHandler handler = new ChainingURSResultHandler();
|
||||
patchDAO.migrateOldAttrChainingURS(handler);
|
||||
|
||||
if (handler.total > 0)
|
||||
{
|
||||
logger.info("Processed "+handler.total+" Chaining URS attrs in "+(System.currentTimeMillis()-startTime)/1000+" secs");
|
||||
}
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
|
||||
private class ChainingURSResultHandler implements ResultHandler
|
||||
{
|
||||
private int total = 0;
|
||||
|
||||
private ChainingURSResultHandler()
|
||||
{
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handleResult(ResultContext context)
|
||||
{
|
||||
Map<String, Object> result = (Map<String, Object>)context.getResultObject();
|
||||
|
||||
String label = (String)result.get("label");
|
||||
String zoneId = (String)result.get("zoneId");
|
||||
Long lastModified = (Long)result.get("lastModified");
|
||||
|
||||
attributeService.setAttribute(
|
||||
lastModified,
|
||||
ChainingUserRegistrySynchronizer.ROOT_ATTRIBUTE_PATH, label, zoneId);
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("Set Chaining URS attr [label="+label+", zoneId="+zoneId+", lastModified="+lastModified+"]");
|
||||
}
|
||||
|
||||
total++;
|
||||
|
||||
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
|
||||
{
|
||||
logger.debug(" Handled " + total + " Chaining URS attributes");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.AttributeList;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ibatis.session.ResultContext;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Migrate Property-Backed Bean attributes (from 'alf_*attribute*' to 'alf_prop_*')
|
||||
*
|
||||
* @author janv
|
||||
* @since 3.4
|
||||
*/
|
||||
public class MigrateAttrPropBackedBeanPatch extends AbstractPatch implements ApplicationContextAware
|
||||
{
|
||||
private Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private static final String ROOT_KEY_PBB = ".PropertyBackedBeans"; // see also PropertyBackBeanAdapter.ROOT_ATTRIBUTE_PATH
|
||||
|
||||
private static final String MSG_SUCCESS = "patch.migrateAttrPropBackedBeans.result";
|
||||
|
||||
private AttributeService attributeService;
|
||||
private PatchDAO patchDAO;
|
||||
private MBeanServerConnection mbeanServer;
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
|
||||
{
|
||||
// Optional dependency - may not exist in community builds
|
||||
this.mbeanServer = (MBeanServerConnection) applicationContext.getBean("alfrescoMBeanServer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
PBBesultHandler handler = new PBBesultHandler();
|
||||
patchDAO.migrateOldAttrPropertyBackedBeans(handler);
|
||||
handler.setComponent(handler.currentComponentName, handler.attributeMap); // set last component attribute (if any)
|
||||
|
||||
if (handler.total > 0)
|
||||
{
|
||||
logger.info("Processed "+handler.total+" Property-Backed Component attrs ("+handler.totalProps+" props) in "+(System.currentTimeMillis()-startTime)/1000+" secs");
|
||||
}
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total, handler.totalProps);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
|
||||
private class PBBesultHandler implements ResultHandler
|
||||
{
|
||||
private int total = 0;
|
||||
private int totalProps = 0;
|
||||
|
||||
private Map<String, String> attributeMap = new HashMap<String, String>(10);
|
||||
private String currentComponentName = "";
|
||||
|
||||
private PBBesultHandler()
|
||||
{
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handleResult(ResultContext context)
|
||||
{
|
||||
Map<String, Object> result = (Map<String, Object>)context.getResultObject();
|
||||
|
||||
String componentName = (String)result.get("componentName");
|
||||
String propName = (String)result.get("propName");
|
||||
String propValue = (String)result.get("propValue");
|
||||
|
||||
if (! currentComponentName.equals(componentName))
|
||||
{
|
||||
// write out previous component - note: does nothing on 1st call
|
||||
setComponent(currentComponentName, attributeMap);
|
||||
|
||||
currentComponentName = componentName;
|
||||
attributeMap.clear();
|
||||
}
|
||||
|
||||
attributeMap.put(propName, propValue);
|
||||
|
||||
totalProps++;
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("Read PBB [componentName="+componentName+", propName="+propName+", propValue="+propValue+"]");
|
||||
}
|
||||
}
|
||||
|
||||
// note: args should not be null
|
||||
public void setComponent(String componentName, Map<String, String> attributeMap)
|
||||
{
|
||||
if (componentName.equals("") || attributeMap.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean done = false;
|
||||
try
|
||||
{
|
||||
// Go through the subsystem MBean interface in case the subsystem is already live and the cluster needs
|
||||
// to be resynced
|
||||
|
||||
// Decode the bean ID to a hierarchical object name
|
||||
String[] components = componentName.split("\\$");
|
||||
StringBuilder nameBuff = new StringBuilder(200).append("Alfresco:Type=Configuration,Category=").append(
|
||||
URLDecoder.decode(components[0], "UTF-8"));
|
||||
for (int i = 1; i < components.length; i++)
|
||||
{
|
||||
nameBuff.append(",id").append(i).append('=').append(URLDecoder.decode(components[i], "UTF-8"));
|
||||
}
|
||||
|
||||
ObjectName name = new ObjectName(nameBuff.toString());
|
||||
if (mbeanServer != null && mbeanServer.isRegistered(name))
|
||||
{
|
||||
AttributeList attributeList = new AttributeList();
|
||||
for (Map.Entry<String, String> entry : attributeMap.entrySet())
|
||||
{
|
||||
attributeList.add(new Attribute(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
mbeanServer.setAttributes(name, attributeList);
|
||||
// We've successfully persisted the attributes. Job done
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger
|
||||
.warn(
|
||||
"Exception migrating attributes of subsystem "
|
||||
+ componentName
|
||||
+ ". Falling back to repository-only operation. Subsystem may remain out of sync until reboot.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: perhaps the subsystem isn't up yet and hasn't exported its bean. Or perhaps an error occurred
|
||||
// above. Let's persist the new property anyway.
|
||||
if (!done)
|
||||
{
|
||||
attributeService.setAttribute((Serializable) attributeMap, ROOT_KEY_PBB, componentName);
|
||||
}
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("Set PBB component attr [name="+componentName+", attributeMap="+attributeMap+"]");
|
||||
}
|
||||
|
||||
total++;
|
||||
|
||||
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
|
||||
{
|
||||
logger.debug(" Handled " + total + " Chaining URS attrs");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.tenant.MultiTAdminServiceImpl;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ibatis.session.ResultContext;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Migrate Tenant attributes (from 'alf_*attribute*' to 'alf_prop_*')
|
||||
*
|
||||
* @author janv
|
||||
* @since 3.4
|
||||
*/
|
||||
public class MigrateAttrTenantsPatch extends AbstractPatch
|
||||
{
|
||||
private Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private static final String MSG_SUCCESS = "patch.migrateAttrTenants.result";
|
||||
|
||||
private AttributeService attributeService;
|
||||
private PatchDAO patchDAO;
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
TenantResultHandler handler = new TenantResultHandler();
|
||||
patchDAO.migrateOldAttrTenants(handler);
|
||||
|
||||
if (handler.total > 0)
|
||||
{
|
||||
logger.info("Processed "+handler.total+" Tenant attrs in "+(System.currentTimeMillis()-startTime)/1000+" secs");
|
||||
}
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Row handler for migrating tenants
|
||||
*/
|
||||
private class TenantResultHandler implements ResultHandler
|
||||
{
|
||||
private int total = 0;
|
||||
|
||||
private TenantResultHandler()
|
||||
{
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handleResult(ResultContext context)
|
||||
{
|
||||
Map<String, Object> result = (Map<String, Object>)context.getResultObject();
|
||||
|
||||
String tenantDomain = (String)result.get("tenantDomain");
|
||||
Boolean isEnabled = (Boolean)result.get("isEnabled");
|
||||
String rootDir = (String)result.get("rootDir");
|
||||
|
||||
Map<String, Serializable> tenantAttributes = new HashMap<String, Serializable>(7);
|
||||
tenantAttributes.put(MultiTAdminServiceImpl.TENANT_ATTRIBUTE_ENABLED, isEnabled.booleanValue());
|
||||
tenantAttributes.put(MultiTAdminServiceImpl.TENANT_ATTRIBUTE_ROOT_CONTENT_STORE_DIR, rootDir);
|
||||
|
||||
attributeService.setAttribute(
|
||||
(Serializable) tenantAttributes,
|
||||
MultiTAdminServiceImpl.TENANTS_ATTRIBUTE_PATH, tenantDomain);
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("Set Tenant attr [tenantDomain="+tenantDomain+", isEnabled="+isEnabled+", rootDir="+rootDir+"]");
|
||||
}
|
||||
|
||||
total++;
|
||||
|
||||
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
|
||||
{
|
||||
logger.debug(" Handled " + total + " tenant attributes");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user