Morning merge.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2889 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-05-14 16:21:55 +00:00
parent f19fa92b31
commit 1d601e1be7
29 changed files with 788 additions and 104 deletions

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.importer.system;
import java.util.Date;
/**
* Data holder of patch information that's to be exported and imported
*
* @author davidc
*/
public class PatchInfo
{
public String id = null;
public String description = null;
public Integer fixesFromSchema = null;
public Integer fixesToSchema = null;
public Integer targetSchema = null;
public Integer appliedToSchema = null;
public String appliedToServer = null;
public Date appliedOnDate = null;
public Boolean wasExecuted = null;
public Boolean succeeded = null;
public String report = null;
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.importer.system;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.alfresco.repo.admin.patch.PatchDaoService;
import org.alfresco.repo.domain.AppliedPatch;
import org.alfresco.repo.domain.hibernate.VersionCounterDaoComponentImpl;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
/**
* Exporter and Importer of Repository System Information
*
* @author davidc
*/
public class SystemExporterImporter
{
// dependencies
private NodeService nodeService;
private PatchDaoService patchDao;
private VersionCounterDaoComponentImpl versionCounterDao;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setPatchDao(PatchDaoService patchDaoService)
{
this.patchDao = patchDaoService;
}
public void setVersionDao(VersionCounterDaoComponentImpl versionCounterDao)
{
this.versionCounterDao = versionCounterDao;
}
/**
* Export Repository System Information
*
* @param exportStream output stream to export to
*/
public void exportSystem(OutputStream exportStream)
{
SystemInfo systemInfo = new SystemInfo();
// capture applied patches
List<AppliedPatch> patches = patchDao.getAppliedPatches();
for (AppliedPatch patch : patches)
{
PatchInfo patchInfo = new PatchInfo();
patchInfo.appliedOnDate = patch.getAppliedOnDate();
patchInfo.appliedToSchema = patch.getAppliedToSchema();
patchInfo.appliedToServer = patch.getAppliedToServer();
patchInfo.description = patch.getDescription();
patchInfo.fixesFromSchema = patch.getFixesFromSchema();
patchInfo.fixesToSchema = patch.getFixesToSchema();
patchInfo.id = patch.getId();
patchInfo.report = patch.getReport();
patchInfo.succeeded = patch.getSucceeded();
patchInfo.targetSchema = patch.getTargetSchema();
patchInfo.wasExecuted = patch.getWasExecuted();
systemInfo.patches.add(patchInfo);
}
// capture version counters
List<StoreRef> storeRefs = nodeService.getStores();
for (StoreRef storeRef : storeRefs)
{
VersionCounterInfo versionCounterInfo = new VersionCounterInfo();
int versionCount = versionCounterDao.currentVersionNumber(storeRef);
versionCounterInfo.storeRef = storeRef.toString();
versionCounterInfo.count = versionCount;
systemInfo.versionCounters.add(versionCounterInfo);
}
systemInfo.toXML(exportStream);
}
/**
* Import Repository System Information
*
* @param importStream input stream to import from
*/
public void importSystem(InputStream importStream)
{
SystemInfo systemInfo = SystemInfo.createSystemInfo(importStream);
// apply patch info
for (PatchInfo patchInfo : systemInfo.patches)
{
AppliedPatch patch = patchDao.newAppliedPatch(patchInfo.id);
patch.setAppliedOnDate(patchInfo.appliedOnDate);
patch.setAppliedToSchema(patchInfo.appliedToSchema);
patch.setAppliedToServer(patchInfo.appliedToServer);
patch.setDescription(patchInfo.description);
patch.setFixesFromSchema(patchInfo.fixesFromSchema);
patch.setFixesToSchema(patchInfo.fixesToSchema);
patch.setReport(patchInfo.report);
patch.setSucceeded(patchInfo.succeeded);
patch.setTargetSchema(patchInfo.targetSchema);
patch.setWasExecuted(patchInfo.wasExecuted);
}
// apply version counters
for (VersionCounterInfo versionCounterInfo : systemInfo.versionCounters)
{
StoreRef storeRef = new StoreRef(versionCounterInfo.storeRef);
versionCounterDao.setVersionNumber(storeRef, versionCounterInfo.count);
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.importer.system;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
/**
* Root data holder of Repository system information to be exported and imported
*
* @author davidc
*/
public class SystemInfo
{
public List<PatchInfo> patches = new ArrayList<PatchInfo>();
public List<VersionCounterInfo> versionCounters = new ArrayList<VersionCounterInfo>();
/**
* Create System Info from XML representation
*
* @param xml xml representation of system info
* @return the System Info
*/
public static SystemInfo createSystemInfo(InputStream xml)
{
try
{
IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class);
IUnmarshallingContext context = factory.createUnmarshallingContext();
Object obj = context.unmarshalDocument(xml, null);
return (SystemInfo)obj;
}
catch(JiBXException e)
{
throw new DictionaryException("Failed to parse System Info", e);
}
}
/**
* Create XML representation of System Info
*
* @param xml xml representation of system info
*/
public void toXML(OutputStream xml)
{
try
{
IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class);
IMarshallingContext context = factory.createMarshallingContext();
context.setIndent(4);
context.marshalDocument(this, "UTF-8", null, xml);
}
catch(JiBXException e)
{
throw new DictionaryException("Failed to create System Info", e);
}
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/package org.alfresco.repo.importer.system;
import java.io.InputStream;
import java.util.List;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.view.ImporterException;
import org.alfresco.service.transaction.TransactionService;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
/**
* Repository System Information bootstrap
*
* @author davidc
*/
public class SystemInfoBootstrap implements ApplicationListener
{
// dependencies
private TransactionService transactionService;
private NodeService nodeService;
private AuthenticationComponent authenticationComponent;
private SystemExporterImporter systemImporter;
private List<String> mustNotExistStoreUrls = null;
private String bootstrapView = null;
/**
* Sets the Transaction Service
*
* @param userTransaction the transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Sets the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the authentication component
*
* @param authenticationComponent
*/
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
{
this.authenticationComponent = authenticationComponent;
}
/**
* Set the System Importer
*
* @param systemImporter
*/
public void setSystemImporter(SystemExporterImporter systemImporter)
{
this.systemImporter = systemImporter;
}
/**
* If any of the store urls exist, the bootstrap does not take place
*
* @param storeUrls the list of store urls to check
*/
public void setMustNotExistStoreUrls(List<String> storeUrls)
{
this.mustNotExistStoreUrls = storeUrls;
}
/**
* Set the bootstrap view containing the system information
*
* @param bootstrapView
*/
public void setBootstrapView(String bootstrapView)
{
this.bootstrapView = bootstrapView;
}
/**
* Bootstrap
*/
public void bootstrap()
{
UserTransaction userTransaction = transactionService.getUserTransaction();
authenticationComponent.setSystemUserAsCurrentUser();
try
{
userTransaction.begin();
// check the repository exists, create if it doesn't
if (performBootstrap())
{
InputStream viewStream = getClass().getClassLoader().getResourceAsStream(bootstrapView);
if (viewStream == null)
{
throw new ImporterException("Could not find system info file " + bootstrapView);
}
try
{
systemImporter.importSystem(viewStream);
}
finally
{
viewStream.close();
}
}
userTransaction.commit();
}
catch(Throwable e)
{
// rollback the transaction
try { if (userTransaction != null) {userTransaction.rollback();} } catch (Exception ex) {}
try {authenticationComponent.clearCurrentSecurityContext(); } catch (Exception ex) {}
throw new AlfrescoRuntimeException("System Info Bootstrap failed", e);
}
finally
{
authenticationComponent.clearCurrentSecurityContext();
}
}
/**
* Determine if bootstrap should take place
*
* @return true => yes, it should
*/
private boolean performBootstrap()
{
if (bootstrapView == null || bootstrapView.length() == 0)
{
return false;
}
if (mustNotExistStoreUrls != null)
{
for (String storeUrl : mustNotExistStoreUrls)
{
StoreRef storeRef = new StoreRef(storeUrl);
if (nodeService.exists(storeRef))
{
return false;
}
}
}
return true;
}
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
bootstrap();
}
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.importer.system;
/**
* Data holder of Version information to be exported and imported
*
* @author davidc
*/
public class VersionCounterInfo
{
public String storeRef = null;
public Integer count = null;
}

View File

@@ -0,0 +1,36 @@
<binding>
<!-- <format type="java.util.Date" serializer="org.alfresco.repo.dictionary.M2XML.serialiseDate" deserializer="org.alfresco.repo.dictionary.M2XML.deserialiseDate"/> -->
<mapping name="system-info" class="org.alfresco.repo.importer.system.SystemInfo">
<structure name="patches">
<collection field="patches" factory="org.alfresco.repo.dictionary.M2Model.createList">
<structure name="patch" type="org.alfresco.repo.importer.system.PatchInfo" usage="optional">
<value name="id" field="id"/>
<value name="description" field="description"/>
<value name="fixes-from-schema" field="fixesFromSchema"/>
<value name="fixes-to-schema" field="fixesToSchema"/>
<value name="target-schema" field="targetSchema"/>
<value name="applied-to-schema" field="appliedToSchema"/>
<value name="applied-to-server" field="appliedToServer"/>
<value name="applied-on-date" field="appliedOnDate"/>
<value name="was-executed" field="wasExecuted"/>
<value name="succeeded" field="succeeded"/>
<value name="report" field="report"/>
</structure>
</collection>
</structure>
<structure name="version-store">
<collection field="versionCounters" factory="org.alfresco.repo.dictionary.M2Model.createList">
<structure name="counter" type="org.alfresco.repo.importer.system.VersionCounterInfo" usage="optional">
<value name="store-ref" field="storeRef"/>
<value name="count" field="count"/>
</structure>
</collection>
</structure>
</mapping>
</binding>