mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Full Repository Export / Import
- support export of system information such as applied patches and version counters - support for deleted archive store git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2884 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
|
||||
<!-- Bootstrap Files -->
|
||||
|
||||
<bean id="systemInfoBootstrap" parent="systemInfoImporter">
|
||||
</bean>
|
||||
|
||||
<bean id="userBootstrap" parent="userStoreImporter">
|
||||
<property name="bootstrapViews">
|
||||
<list>
|
||||
|
@@ -3,6 +3,12 @@
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="systemInfoBootstrap" parent="systemInfoImporter">
|
||||
<property name="bootstrapView">
|
||||
<value>alfresco/extension/restore/export_systeminfo.xml</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="userBootstrap" parent="userStoreImporter">
|
||||
<property name="bootstrapViews">
|
||||
<list>
|
||||
@@ -39,6 +45,17 @@
|
||||
<property name="log"><value>true</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="spacesArchiveBootstrap" parent="spacesArchiveStoreImporter">
|
||||
<property name="bootstrapViews">
|
||||
<list>
|
||||
<props>
|
||||
<prop key="path">/</prop>
|
||||
<prop key="location">alfresco/extension/restore/export_spaces_archive.acp</prop>
|
||||
</props>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="spacesBootstrap" parent="spacesStoreImporter">
|
||||
<property name="bootstrapViews">
|
||||
<list>
|
||||
|
@@ -94,6 +94,9 @@
|
||||
<property name="nodeService">
|
||||
<ref bean="NodeService" />
|
||||
</property>
|
||||
<property name="systemExporter">
|
||||
<ref bean="systemExporterImporter" />
|
||||
</property>
|
||||
<property name="stores">
|
||||
<list>
|
||||
<props>
|
||||
@@ -108,6 +111,10 @@
|
||||
<prop key="storeRef">${spaces.store}</prop>
|
||||
<prop key="packageName">spaces</prop>
|
||||
</props>
|
||||
<props>
|
||||
<prop key="storeRef">${spaces.archive.store}</prop>
|
||||
<prop key="packageName">spaces_archive</prop>
|
||||
</props>
|
||||
<props>
|
||||
<prop key="storeRef">workspace://lightWeightVersionStore</prop>
|
||||
<prop key="packageName">versions</prop>
|
||||
@@ -116,6 +123,40 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="systemExporterImporter" class="org.alfresco.repo.importer.system.SystemExporterImporter">
|
||||
<property name="nodeService">
|
||||
<ref bean="nodeService" />
|
||||
</property>
|
||||
<property name="patchDao">
|
||||
<ref bean="patchDaoComponent" />
|
||||
</property>
|
||||
<property name="versionDao">
|
||||
<ref bean="versionCounterDaoComponent" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- System Info Importer -->
|
||||
|
||||
<bean id="systemInfoImporter" class="org.alfresco.repo.importer.system.SystemInfoBootstrap" abstract="true">
|
||||
<property name="transactionService">
|
||||
<ref bean="transactionComponent"/>
|
||||
</property>
|
||||
<property name="nodeService">
|
||||
<ref bean="nodeService"/>
|
||||
</property>
|
||||
<property name="authenticationComponent">
|
||||
<ref bean="authenticationComponent" />
|
||||
</property>
|
||||
<property name="systemImporter">
|
||||
<ref bean="systemExporterImporter" />
|
||||
</property>
|
||||
<property name="mustNotExistStoreUrls">
|
||||
<list>
|
||||
<value>${system.store}</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- General Repository Store Importer -->
|
||||
|
||||
|
@@ -69,7 +69,8 @@ export.title=Export a Space
|
||||
export.description=Exports a Space and optionally it's children to an Alfresco export package.
|
||||
export.package.description=Alfresco content package for Space ''{0}''.
|
||||
export.root.package.description=Alfresco content package for complete Repository.
|
||||
export.store.package.description=Alfresco export of store ''{0}''.
|
||||
export.store.package.description=Alfresco Repository export of store ''{0}''.
|
||||
export.generic.package.description=Alfresco Repository export.
|
||||
export.package.error=Failed to find temporary file for export
|
||||
|
||||
script.title=Execute a script
|
||||
|
@@ -9,9 +9,12 @@
|
||||
</target>
|
||||
|
||||
<target name="compile-jibx" depends="init">
|
||||
<bind verbose="false" load="true" binding="${file.jibx.binding}">
|
||||
<bind verbose="false" load="true" binding="${file.jibx.binding.m2}">
|
||||
<classpathset dir="${dir.classes}"/>
|
||||
</bind>
|
||||
<bind verbose="false" load="true" binding="${file.jibx.binding.systeminfo}">
|
||||
<classpathset dir="${dir.classes}"/>
|
||||
</bind>
|
||||
</target>
|
||||
|
||||
<target name="build-single-jar" depends="common.compile-java" description="Build an self-contained executable jar" >
|
||||
|
@@ -1,4 +1,5 @@
|
||||
file.jibx.binding=${dir.src.java}/org/alfresco/repo/dictionary/m2binding.xml
|
||||
file.jibx.binding.m2=${dir.src.java}/org/alfresco/repo/dictionary/m2binding.xml
|
||||
file.jibx.binding.systeminfo=${dir.src.java}/org/alfresco/repo/importer/system/systeminfo.xml
|
||||
dir.javadoc.api.service=${dir.docs}/java-public-service-api
|
||||
|
||||
tck.webinf.lib.excludes=${webinf.lib.excludes},jcr-1.0.jar
|
||||
|
@@ -56,4 +56,11 @@ public interface VersionCount
|
||||
* @see #incrementVersionCount()
|
||||
*/
|
||||
public int getVersionCount();
|
||||
|
||||
/**
|
||||
* Sets the current version counter
|
||||
*
|
||||
* @param versionCount the new version counter
|
||||
*/
|
||||
public void setVersionCount(int versionCount);
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ public class VersionCountImpl implements VersionCount
|
||||
/**
|
||||
* For Hibernate use
|
||||
*/
|
||||
private void setVersionCount(int versionCount)
|
||||
public void setVersionCount(int versionCount)
|
||||
{
|
||||
this.versionCount = versionCount;
|
||||
}
|
||||
|
@@ -179,4 +179,22 @@ public class VersionCounterDaoComponentImpl
|
||||
// get an incremented count
|
||||
versionCounter.resetVersionCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version number for a specified store.
|
||||
*
|
||||
* WARNING: calling this method will completely reset the current
|
||||
* version count for the specified store and cannot be undone.
|
||||
*
|
||||
* @param storeRef the store reference
|
||||
* @param versionCount the new version count
|
||||
*/
|
||||
public synchronized void setVersionNumber(StoreRef storeRef, int versionCount)
|
||||
{
|
||||
// get the version counter
|
||||
VersionCount versionCounter = getVersionCounter(storeRef);
|
||||
// get an incremented count
|
||||
versionCounter.setVersionCount(versionCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import java.util.Properties;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.importer.system.SystemExporterImporter;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
@@ -64,6 +65,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
private ExporterService exporterService;
|
||||
private MimetypeService mimetypeService;
|
||||
private FileFolderService fileFolderService;
|
||||
private SystemExporterImporter systemExporterImporter;
|
||||
private NodeService nodeService;
|
||||
private List<Properties> exportStores;
|
||||
|
||||
@@ -82,6 +84,11 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
public void setSystemExporter(SystemExporterImporter systemExporterImporter)
|
||||
{
|
||||
this.systemExporterImporter = systemExporterImporter;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
@@ -104,7 +111,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
return exportHandles.toArray(new FileExportHandle[exportHandles.size()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.RepositoryExporterService#export(java.io.File)
|
||||
@@ -136,14 +143,27 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
}
|
||||
|
||||
List<FileExportHandle> exportHandles = exportStores(exportStores, packageName, new TempFileExporter());
|
||||
Map<String, String> mimetypeExtensions = mimetypeService.getExtensionsByMimetype();
|
||||
List<RepositoryExportHandle> repoExportHandles = new ArrayList<RepositoryExportHandle>(exportHandles.size());
|
||||
for (FileExportHandle exportHandle : exportHandles)
|
||||
{
|
||||
String description = I18NUtil.getMessage("export.store.package.description", new Object[] { exportHandle.storeRef.getIdentifier() });
|
||||
NodeRef repoExportFile = addExportFile(repositoryDestination, exportHandle.packageName, description, exportHandle.exportFile);
|
||||
String name = exportHandle.packageName + "." + mimetypeExtensions.get(exportHandle.mimeType);
|
||||
String title = exportHandle.packageName;
|
||||
String description;
|
||||
if (exportHandle.storeRef != null)
|
||||
{
|
||||
description = I18NUtil.getMessage("export.store.package.description", new Object[] { exportHandle.storeRef.toString() });
|
||||
}
|
||||
else
|
||||
{
|
||||
description = I18NUtil.getMessage("export.generic.package.description");
|
||||
}
|
||||
|
||||
NodeRef repoExportFile = addExportFile(repositoryDestination, name, title, description, exportHandle.mimeType, exportHandle.exportFile);
|
||||
RepositoryExportHandle handle = new RepositoryExportHandle();
|
||||
handle.storeRef = exportHandle.storeRef;
|
||||
handle.packageName = exportHandle.packageName;
|
||||
handle.mimeType = exportHandle.mimeType;
|
||||
handle.exportFile = repoExportFile;
|
||||
repoExportHandles.add(handle);
|
||||
}
|
||||
@@ -161,16 +181,15 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
* @param exportFile the .acp file
|
||||
* @return node reference to import .acp file
|
||||
*/
|
||||
private NodeRef addExportFile(NodeRef repoDestination, String packageName, String packageDescription, File exportFile)
|
||||
private NodeRef addExportFile(NodeRef repoDestination, String name, String title, String description, String mimeType, File exportFile)
|
||||
{
|
||||
//
|
||||
// import temp file into repository
|
||||
//
|
||||
|
||||
// determine if file already exists
|
||||
String fileName = packageName + "." + ACPExportPackageHandler.ACP_EXTENSION;
|
||||
List<String> paths = new ArrayList<String>();
|
||||
paths.add(fileName);
|
||||
paths.add(name);
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(repoDestination, paths);
|
||||
@@ -186,16 +205,16 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
NodeRef exportFileNodeRef = null;
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = fileFolderService.create(repoDestination, fileName, ContentModel.TYPE_CONTENT);
|
||||
FileInfo fileInfo = fileFolderService.create(repoDestination, name, ContentModel.TYPE_CONTENT);
|
||||
ContentWriter writer = fileFolderService.getWriter(fileInfo.getNodeRef());
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_ACP);
|
||||
writer.setMimetype(mimeType);
|
||||
writer.putContent(exportFile);
|
||||
exportFileNodeRef = fileInfo.getNodeRef();
|
||||
|
||||
// add a title for Web Client viewing
|
||||
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
|
||||
titledProps.put(ContentModel.PROP_TITLE, packageName);
|
||||
titledProps.put(ContentModel.PROP_DESCRIPTION, packageDescription);
|
||||
titledProps.put(ContentModel.PROP_TITLE, title);
|
||||
titledProps.put(ContentModel.PROP_DESCRIPTION, description);
|
||||
nodeService.addAspect(exportFileNodeRef, ContentModel.ASPECT_TITLED, titledProps);
|
||||
|
||||
}
|
||||
@@ -209,7 +228,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
|
||||
|
||||
/**
|
||||
* Contract for exporting a store
|
||||
* Contract for exporting a repository
|
||||
*
|
||||
* @author davidc
|
||||
*
|
||||
@@ -218,6 +237,8 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
private interface ExportStore<ExportHandleType extends ExportHandle>
|
||||
{
|
||||
public ExportHandleType exportStore(ExporterCrawlerParameters exportParameters, String packageName, Exporter progress);
|
||||
|
||||
public ExportHandleType exportSystem(String packageName);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +252,16 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
*/
|
||||
private <ExportHandleType extends ExportHandle> List<ExportHandleType> exportStores(List<Properties> stores, String packageName, ExportStore<ExportHandleType> exportStore)
|
||||
{
|
||||
List<ExportHandleType> exportHandles = new ArrayList<ExportHandleType>(stores.size());
|
||||
List<ExportHandleType> exportHandles = new ArrayList<ExportHandleType>(stores.size() +1);
|
||||
|
||||
// export repository system info
|
||||
{
|
||||
String completePackageName = (packageName == null) ? "systeminfo" : packageName + "_systeminfo";
|
||||
ExportHandleType systemInfoHandle = exportStore.exportSystem(completePackageName);
|
||||
exportHandles.add(systemInfoHandle);
|
||||
}
|
||||
|
||||
// export each store
|
||||
for (Properties store : stores)
|
||||
{
|
||||
// retrieve store reference to export
|
||||
@@ -319,9 +349,39 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
FileExportHandle handle = new FileExportHandle();
|
||||
handle.storeRef = exportParameters.getExportFrom().getStoreRef();
|
||||
handle.packageName = packageName;
|
||||
handle.mimeType = MimetypeMap.MIMETYPE_ACP;
|
||||
handle.exportFile = tempFile;
|
||||
return handle;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.exporter.RepositoryExporterComponent.ExportStore#exportSystem()
|
||||
*/
|
||||
public FileExportHandle exportSystem(String packageName)
|
||||
{
|
||||
// create a temporary file to hold the system info export
|
||||
File tempFile = TempFileProvider.createTempFile("repoExpSystemInfo", ".xml");
|
||||
|
||||
try
|
||||
{
|
||||
OutputStream outputStream = new FileOutputStream(tempFile);
|
||||
systemExporterImporter.exportSystem(outputStream);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
tempFile.delete();
|
||||
throw new ExporterException("Failed to create temporary file for holding export of system info");
|
||||
}
|
||||
|
||||
// return handle onto temp file
|
||||
FileExportHandle handle = new FileExportHandle();
|
||||
handle.storeRef = null;
|
||||
handle.packageName = packageName;
|
||||
handle.mimeType = MimetypeMap.MIMETYPE_XML;
|
||||
handle.exportFile = tempFile;
|
||||
return handle;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -374,50 +434,40 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
FileExportHandle handle = new FileExportHandle();
|
||||
handle.storeRef = exportParameters.getExportFrom().getStoreRef();
|
||||
handle.packageName = packageName;
|
||||
handle.mimeType = MimetypeMap.MIMETYPE_ACP;
|
||||
handle.exportFile = file;
|
||||
return handle;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Export a store to Repository File
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private class RepositoryFileExporter implements ExportStore<RepositoryExportHandle>
|
||||
{
|
||||
private TempFileExporter tempFileExporter = new TempFileExporter();
|
||||
private NodeRef repoDestination;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param repoDestination destination within repository to create export file
|
||||
*/
|
||||
public RepositoryFileExporter(NodeRef repoDestination)
|
||||
{
|
||||
this.repoDestination = repoDestination;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.exporter.RepositoryExporterComponent.ExportStore#exportStore(org.alfresco.service.cmr.view.ExporterCrawlerParameters, java.lang.String, org.alfresco.service.cmr.view.Exporter)
|
||||
*/
|
||||
public RepositoryExportHandle exportStore(ExporterCrawlerParameters exportParameters, String packageName, Exporter progress)
|
||||
{
|
||||
// export acp to temporary file
|
||||
FileExportHandle tempFile = tempFileExporter.exportStore(exportParameters, packageName, progress);
|
||||
|
||||
String description = I18NUtil.getMessage("export.store.package.description", new Object[] { tempFile.storeRef.getIdentifier() });
|
||||
NodeRef repoExportFile = addExportFile(repoDestination, packageName, description, tempFile.exportFile);
|
||||
RepositoryExportHandle handle = new RepositoryExportHandle();
|
||||
handle.storeRef = exportParameters.getExportFrom().getStoreRef();
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.exporter.RepositoryExporterComponent.ExportStore#exportSystem()
|
||||
*/
|
||||
public FileExportHandle exportSystem(String packageName)
|
||||
{
|
||||
// create a temporary file to hold the system info export
|
||||
File tempFile = TempFileProvider.createTempFile("repoExpSystemInfo", ".xml");
|
||||
|
||||
try
|
||||
{
|
||||
OutputStream outputStream = new FileOutputStream(tempFile);
|
||||
systemExporterImporter.exportSystem(outputStream);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
tempFile.delete();
|
||||
throw new ExporterException("Failed to create temporary file for holding export of system info");
|
||||
}
|
||||
|
||||
// return handle onto temp file
|
||||
FileExportHandle handle = new FileExportHandle();
|
||||
handle.storeRef = null;
|
||||
handle.packageName = packageName;
|
||||
handle.exportFile = repoExportFile;
|
||||
handle.mimeType = MimetypeMap.MIMETYPE_XML;
|
||||
handle.exportFile = tempFile;
|
||||
return handle;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@@ -64,13 +64,13 @@ public class RepositoryExporterComponentTest extends BaseSpringTest
|
||||
{
|
||||
FileExportHandle[] handles = repositoryService.export("test");
|
||||
assertNotNull(handles);
|
||||
assertEquals(4, handles.length);
|
||||
assertEquals(6, handles.length);
|
||||
for (FileExportHandle tempFile : handles)
|
||||
{
|
||||
assertTrue(tempFile.exportFile.exists());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void xtestRepositoryExport()
|
||||
throws Exception
|
||||
{
|
||||
@@ -82,7 +82,7 @@ public class RepositoryExporterComponentTest extends BaseSpringTest
|
||||
// Export stores
|
||||
RepositoryExportHandle[] handles = repositoryService.export(container.getNodeRef(), "test");
|
||||
assertNotNull(handles);
|
||||
assertEquals(4, handles.length);
|
||||
assertEquals(6, handles.length);
|
||||
for (RepositoryExportHandle handle : handles)
|
||||
{
|
||||
assertTrue(nodeService.exists(handle.exportFile));
|
||||
|
@@ -55,7 +55,6 @@ import org.apache.log4j.Logger;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
|
39
source/java/org/alfresco/repo/importer/system/PatchInfo.java
Normal file
39
source/java/org/alfresco/repo/importer/system/PatchInfo.java
Normal 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;
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
36
source/java/org/alfresco/repo/importer/system/systeminfo.xml
Normal file
36
source/java/org/alfresco/repo/importer/system/systeminfo.xml
Normal 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>
|
@@ -70,6 +70,7 @@ public interface RepositoryExporterService
|
||||
{
|
||||
public StoreRef storeRef;
|
||||
public String packageName;
|
||||
public String mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user