Skip to content

Adding support for permalinks retro compatibility #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/main/java/org/silverpeas/dbbuilder/DBBuilder.java
Original file line number Diff line number Diff line change
@@ -59,6 +59,8 @@

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.jdom.Element;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@@ -268,19 +270,13 @@ public static void main(String[] args) {
// retour sans les retraiter
if (ACTION_INSTALL == params.getAction()) {
processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_INSTALL);
} else if (ACTION_UNINSTALL == params.getAction()
|| ACTION_ENFORCE_UNINSTALL == params.getAction()) {
} else if (ACTION_UNINSTALL == params.getAction() || ACTION_ENFORCE_UNINSTALL == params.
getAction()) {
processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_UNINSTALL);
} else if (ACTION_OPTIMIZE == params.getAction()) {
processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_OPTIMIZE);
} else if (ACTION_ALL == params.getAction()) {
processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_ALL);
} else if (ACTION_STATUS == params.getAction()) {
// nothing to do
} else if (ACTION_CONSTRAINTS_INSTALL == params.getAction()) {
// nothing to do
} else if (ACTION_CONSTRAINTS_UNINSTALL == params.getAction()) {
// nothing to do
}
// Modules en place sur la BD en final
console.printMessage("Finally DB Status :");
@@ -451,10 +447,6 @@ public static void mergeActionsToDo(DBBuilderItem pdbbuilderItem, DBXmlDocument

private static void processDB(DBXmlDocument xmlFile, UninstallInformations processesToCacheIntoDB,
MetaInstructions sqlMetaInstructions, String[] tagsToProcess) throws Exception {
// ------------------------------------------
// ETAPE 1 : TRAITEMENT DES ACTIONS D'UPGRADE
// ------------------------------------------
// Get the root element
Element root = xmlFile.getDocument().getRootElement();
@SuppressWarnings("unchecked")
List<Element> modules = root.getChildren(DBXmlDocument.ELT_MODULE);
@@ -681,18 +673,22 @@ private static String getCleanPath(String name) {
private static DBXmlDocument loadMasterContribution(File dirXml) throws IOException,
AppBuilderException {
DBXmlDocument destXml = new DBXmlDocument(dirXml, MASTER_DBCONTRIBUTION_FILE);
destXml.setOutputEncoding(CharEncoding.UTF_8);
if (!destXml.getPath().exists()) {
destXml.getPath().createNewFile();
BufferedWriter destXmlOut = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(destXml.getPath(), false), Charsets.UTF_8));
destXmlOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
destXmlOut.newLine();
destXmlOut.write("<allcontributions>");
destXmlOut.newLine();
destXmlOut.write("</allcontributions>");
destXmlOut.newLine();
destXmlOut.flush();
destXmlOut.close();
try {
destXmlOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
destXmlOut.newLine();
destXmlOut.write("<allcontributions>");
destXmlOut.newLine();
destXmlOut.write("</allcontributions>");
destXmlOut.newLine();
destXmlOut.flush();
} finally {
IOUtils.closeQuietly(destXmlOut);
}
}
destXml.load();
return destXml;
Original file line number Diff line number Diff line change
@@ -20,12 +20,12 @@
*/
package org.silverpeas.dbbuilder;

import org.silverpeas.util.Console;
import java.sql.Connection;

import org.silverpeas.dbbuilder.dbbuilder_dl.DbBuilderDynamicPart;
import org.silverpeas.dbbuilder.util.Configuration;
import org.silverpeas.dbbuilder.util.DynamicLoader;
import org.silverpeas.util.Console;
import org.silverpeas.util.SilverpeasHomeResolver;

public class DBBuilderDynamicLibPiece extends DBBuilderPiece {
@@ -97,4 +97,12 @@ public void setInstructions() {
public void cacheIntoDB(Connection connection, String _package, int _itemOrder) throws Exception {
// rien à cacher pour une proc dynamique
}

@Override
public void setConnection(Connection connection) {
super.setConnection(connection);
if(dynamicPart != null) {
dynamicPart.setConnection(connection);
}
}
}
10 changes: 8 additions & 2 deletions src/main/java/org/silverpeas/dbbuilder/DBXmlDocument.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@

import org.silverpeas.applicationbuilder.AppBuilderException;
import org.silverpeas.applicationbuilder.ApplicationBuilderItem;
import org.silverpeas.util.StringUtil;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
@@ -64,7 +65,6 @@ public class DBXmlDocument extends ApplicationBuilderItem {
public static final String ELT_MODULE = "module";
public static final String ATT_MODULE_ID = "id";
public static final String ATT_MODULE_VERSION = "version";

private XMLOutputter outputter = defineOutputter();
/**
* @since 1.0
@@ -421,10 +421,16 @@ public String[] getAttributeValues(String attributeToFind) {
}

private XMLOutputter getOutputter() {
if (this.outputter == null) {
this.outputter = defineOutputter();
}
return outputter;
}

private XMLOutputter defineOutputter() {
if (!StringUtil.isDefined(this.outputEncoding)) {
this.outputEncoding = CharEncoding.UTF_8;
}
Format format = Format.getPrettyFormat();
format.setTextMode(TextMode.TRIM);
format.setEncoding(outputEncoding);
@@ -486,5 +492,5 @@ public void mergeWith(DBBuilderItem dbbuilderItem, String[] tagsToMerge,
}
}
setDocument(new Document(root));
}
}
}
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@


import java.sql.Connection;

import org.silverpeas.util.Console;

/**
@@ -55,11 +56,7 @@ public void setSILVERPEAS_DATA(String sh) throws Exception {
SILVERPEAS_DATA = sh;
}

public void setConnection(Connection con) throws Exception {
if (this.con != null) {
throw new Exception(
"DbBuilderDynamicPart.setConnection() fatal error : Connection is already set.");
}
public void setConnection(Connection con) {
this.con = con;
}

Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.logging.Level;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.silverpeas.util.jndi.SimpleMemoryContextFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.silverpeas.util.jndi.SimpleMemoryContextFactory;

/**
* Utility class for obtaining a connection to the database.
@@ -72,7 +72,9 @@ public void setDatasource(DataSource datasource) {
}

public static Connection getConnection() throws SQLException {
return getInstance().datasource.getConnection();
Connection connection = getInstance().datasource.getConnection();
connection.setAutoCommit(false);
return connection;
}

public static String getConnectionInfo() throws SQLException {
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
package org.silverpeas.migration.jcr.service.repository;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jcr.Node;
@@ -35,19 +34,22 @@
import javax.jcr.version.VersionIterator;
import javax.jcr.version.VersionManager;

import org.apache.jackrabbit.core.state.NoSuchItemStateException;

import org.silverpeas.migration.jcr.service.AbstractJcrConverter;
import org.silverpeas.migration.jcr.service.ConverterUtil;
import org.silverpeas.migration.jcr.service.model.DocumentType;
import org.silverpeas.migration.jcr.service.model.HistorisedDocument;
import org.silverpeas.migration.jcr.service.model.HistoryDocumentSorter;
import org.silverpeas.migration.jcr.service.model.SimpleAttachment;
import org.silverpeas.migration.jcr.service.model.SimpleDocument;
import org.silverpeas.migration.jcr.service.model.SimpleDocumentPK;
import org.silverpeas.migration.jcr.service.AbstractJcrConverter;
import org.silverpeas.migration.jcr.service.ConverterUtil;
import org.silverpeas.util.StringUtil;

import static org.silverpeas.migration.jcr.service.JcrConstants.*;
import org.apache.jackrabbit.core.state.NoSuchItemStateException;

import static javax.jcr.Property.JCR_FROZEN_PRIMARY_TYPE;
import static javax.jcr.Property.JCR_LAST_MODIFIED_BY;
import static javax.jcr.nodetype.NodeType.MIX_SIMPLE_VERSIONABLE;
import static org.silverpeas.migration.jcr.service.JcrConstants.*;

/**
*
@@ -68,13 +70,15 @@ List<SimpleDocument> convertDocumentHistory(Node node, String lang) throws
RepositoryException {
try {
VersionManager versionManager = node.getSession().getWorkspace().getVersionManager();
VersionHistory history = versionManager.getVersionHistory(node.getPath());

String path = node.getPath();
VersionHistory history = versionManager.getVersionHistory(path);
Version root = history.getRootVersion();
String rootId = "";
if (root != null) {
rootId = root.getIdentifier();
}
Version base = versionManager.getBaseVersion(node.getPath());
Version base = versionManager.getBaseVersion(path);
String baseId = "";
if (base != null) {
baseId = base.getIdentifier();
@@ -91,6 +95,7 @@ List<SimpleDocument> convertDocumentHistory(Node node, String lang) throws
documentHistory.add(versionDocument);
}
}
HistoryDocumentSorter.sortHistory(documentHistory);
return documentHistory;
} catch (RepositoryException ex) {
if (ex.getCause() instanceof NoSuchItemStateException) {
@@ -107,17 +112,31 @@ public SimpleDocument convertNode(Node node, String lang) throws RepositoryExcep
document.setHistory(history);
return document;
}
if (node.getParent() != null && node.getParent() instanceof Version) {
//We are accessing a version directly throught its id
HistorisedDocument document = new HistorisedDocument(fillDocument(node, lang));
Node fullNode = getCurrentNodeForVersion((Version)node.getParent());
document.setHistory(convertDocumentHistory(fullNode, lang));
return document;
}
return fillDocument(node, lang);
}

public Node getCurrentNodeForVersion(Version version) throws RepositoryException {
String uuid = version.getContainingHistory().getVersionableIdentifier();
return version.getSession().getNodeByIdentifier(uuid);
}

/**
* Convert a NodeIteraor into a collection of SimpleDocument.
*
* @param iter th NodeIterator to convert.
* @param language the language of the wanted document.
* @return a collection of SimpleDocument.
* @throws RepositoryException
*/
public List<SimpleDocument> convertNodeIterator(NodeIterator iter, String language) throws RepositoryException {
public List<SimpleDocument> convertNodeIterator(NodeIterator iter, String language) throws
RepositoryException {
List<SimpleDocument> result = new ArrayList<SimpleDocument>((int) iter.getSize());
while (iter.hasNext()) {
result.add(convertNode(iter.nextNode(), language));
Loading
Oops, something went wrong.