0001: /**
0002: * LibreSource
0003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
0004: * http://www.libresource.org - contact@artenum.com
0005: *
0006: * This file is part of the LibreSource software,
0007: * which can be used and distributed under license conditions.
0008: * The license conditions are provided in the LICENSE.TXT file
0009: * at the root path of the packaging that enclose this file.
0010: * More information can be found at
0011: * - http://dev.libresource.org/home/license
0012: *
0013: * Initial authors :
0014: *
0015: * Guillaume Bort / INRIA
0016: * Francois Charoy / Universite Nancy 2
0017: * Julien Forest / Artenum
0018: * Claude Godart / Universite Henry Poincare
0019: * Florent Jouille / INRIA
0020: * Sebastien Jourdain / INRIA / Artenum
0021: * Yves Lerumeur / Artenum
0022: * Pascal Molli / Universite Henry Poincare
0023: * Gerald Oster / INRIA
0024: * Mariarosa Penzi / Artenum
0025: * Gerard Sookahet / Artenum
0026: * Raphael Tani / INRIA
0027: *
0028: * Contributors :
0029: *
0030: * Stephane Bagnier / Artenum
0031: * Amadou Dia / Artenum-IUP Blois
0032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0033: */package org.libresource.so6.server.ls.ejb;
0034:
0035: import org.apache.xml.serialize.OutputFormat;
0036: import org.apache.xml.serialize.XMLSerializer;
0037:
0038: import org.libresource.Libresource;
0039: import org.libresource.LibresourceEvent;
0040: import org.libresource.LibresourceException;
0041: import org.libresource.LibresourceResourceIdentifier;
0042: import org.libresource.LibresourceResourceValue;
0043: import org.libresource.LibresourceServiceBase;
0044:
0045: import org.libresource.core.CoreConstants;
0046: import org.libresource.core.FileData;
0047: import org.libresource.core.FileDataImpl;
0048: import org.libresource.core.interfaces.LibresourceCoreService;
0049: import org.libresource.core.util.LibresourceCoreServiceUtil;
0050:
0051: import org.libresource.kernel.KernelConstants;
0052: import org.libresource.kernel.KernelServiceException;
0053: import org.libresource.kernel.LibresourceSecurityException;
0054: import org.libresource.kernel.URINotExistException;
0055: import org.libresource.kernel.interfaces.KernelService;
0056:
0057: import org.libresource.search.LibresourceIndexableContent;
0058:
0059: import org.libresource.so6.core.compress.CompressUtil;
0060: import org.libresource.so6.core.engine.OpVectorFsImpl;
0061: import org.libresource.so6.core.engine.PatchFile;
0062: import org.libresource.so6.core.engine.util.FileUtils;
0063: import org.libresource.so6.server.ls.InvalideTicketException;
0064: import org.libresource.so6.server.ls.LibresourceSynchronizerConstants;
0065: import org.libresource.so6.server.ls.LibresourceSynchronizerException;
0066: import org.libresource.so6.server.ls.PatchBean;
0067: import org.libresource.so6.server.ls.SynchronizerExportHandler;
0068: import org.libresource.so6.server.ls.SynchronizerImportHandler;
0069: import org.libresource.so6.server.ls.WsConnectionExportHandler;
0070: import org.libresource.so6.server.ls.WsConnectionImportHandler;
0071: import org.libresource.so6.server.ls.ejb.model.SynchronizerResourceValue;
0072: import org.libresource.so6.server.ls.ejb.model.WorkspaceValue;
0073: import org.libresource.so6.server.ls.ejb.model.WsConnectionResourceValue;
0074: import org.libresource.so6.server.ls.interfaces.LibresourceSynchronizerService;
0075: import org.libresource.so6.server.ls.interfaces.SynchronizerResourceLocal;
0076: import org.libresource.so6.server.ls.interfaces.WorkspaceLocal;
0077: import org.libresource.so6.server.ls.interfaces.WsConnectionResourceLocal;
0078: import org.libresource.so6.server.ls.util.SynchronizerResourceUtil;
0079: import org.libresource.so6.server.ls.util.WorkspaceUtil;
0080: import org.libresource.so6.server.ls.util.WsConnectionResourceUtil;
0081:
0082: import org.libresource.xml.LibresourceExportHandler;
0083: import org.libresource.xml.LibresourceImportHandler;
0084:
0085: import org.xml.sax.SAXException;
0086: import org.xml.sax.helpers.AttributeListImpl;
0087:
0088: import java.io.BufferedInputStream;
0089: import java.io.BufferedOutputStream;
0090: import java.io.File;
0091: import java.io.FileInputStream;
0092: import java.io.FileOutputStream;
0093: import java.io.FileWriter;
0094: import java.io.IOException;
0095: import java.io.OutputStreamWriter;
0096:
0097: import java.net.URI;
0098:
0099: import java.sql.Connection;
0100: import java.sql.PreparedStatement;
0101: import java.sql.ResultSet;
0102: import java.sql.SQLException;
0103: import java.sql.Statement;
0104: import java.sql.Timestamp;
0105:
0106: import java.util.ArrayList;
0107: import java.util.Collection;
0108: import java.util.Date;
0109: import java.util.Hashtable;
0110: import java.util.Iterator;
0111: import java.util.Vector;
0112:
0113: import javax.ejb.FinderException;
0114:
0115: import javax.naming.NamingException;
0116:
0117: /**
0118: * The Libresource Sycnhronization service
0119: *
0120: * @author <a href="mailto:jourdain@loria.fr">Sebastien Jourdain</a> - <a
0121: * href="http://www.inria.fr">INRIA Lorraine</a>
0122: *
0123: * @libresource.service name="LibresourceSynchronizer"
0124: * depends="Kernel,Membership,LibresourceCore"
0125: *
0126: * Mise a jour Janvier 2005
0127: * @author Sebastien (Artenum) Reecriture des methodes de generation du dataflow
0128: */
0129: public abstract class LibresourceSynchronizerServiceBean extends
0130: LibresourceServiceBase {
0131: // static {
0132: // try {
0133: // KernelService kernelService = (KernelService)
0134: // Libresource.getService(KernelConstants.SERVICE);
0135: // LibresourceJob job = new
0136: // LibresourceJob("libresourceSynchronizer.compressHistory", new
0137: // Hashtable());
0138: // kernelService.scheduleJob(job, "Compress synchronizers history", "0 0 23
0139: // * * ?");
0140: // } catch (Exception e) {
0141: // e.printStackTrace();
0142: // }
0143: // }
0144: public final static String SO6_CREATE_WORKSPACE = "SO6:CREATE_WS";
0145: public final static String SO6_COMMIT = "SO6:COMMIT";
0146:
0147: //
0148: public final static int BUFFER_SIZE = 1048576;
0149:
0150: //
0151: public final static String DEFAULT_BINARY_EXTENTION = "pdf ps eps zip class gif jpg mp3 mpg png";
0152: public final static String PATCH_TABLE_PARAM = " ( fromTicket_ INT8 ,toTicket_ INT8 , xmlPatch_ OID, xmlPatchSize_ INT4, wsName_ TEXT, comment_ TEXT, time_ TIMESTAMP(3), baseLine_ OID, builtPatch Boolean, tagName_ TEXT, changeLog_ TEXT,tagged_ Boolean)";
0153:
0154: /**
0155: * @ejb.interface-method
0156: * @ejb.transaction type="Required"
0157: */
0158: public void createSynchronizer(URI uri, String name,
0159: String description, String binExt)
0160: throws LibresourceSynchronizerException,
0161: LibresourceSecurityException, URINotExistException {
0162: try {
0163: KernelService kernelService = (KernelService) Libresource
0164: .getService(KernelConstants.SERVICE);
0165: SynchronizerResourceLocal synchronizerResourceLocal = SynchronizerResourceUtil
0166: .getLocalHome().create(name, description);
0167:
0168: if (binExt != null) {
0169: synchronizerResourceLocal.setBinaryExtention(binExt);
0170: } else {
0171: synchronizerResourceLocal
0172: .setBinaryExtention(DEFAULT_BINARY_EXTENTION);
0173: }
0174:
0175: kernelService.bind(synchronizerResourceLocal
0176: .getLibresourceResourceIdentifier(), uri, name);
0177:
0178: // event
0179: LibresourceEvent event = new LibresourceEvent(
0180: uri,
0181: synchronizerResourceLocal
0182: .getLibresourceResourceIdentifier(),
0183: kernelService.getConnectedResource(),
0184: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_CREATE);
0185: Libresource.throwEvent(event);
0186: } catch (LibresourceSecurityException se) {
0187: ctx.setRollbackOnly();
0188: throw se;
0189: } catch (Exception e) {
0190: ctx.setRollbackOnly();
0191: throw new LibresourceSynchronizerException(
0192: "Error in createSynchronizer : " + e.getMessage(),
0193: e);
0194: }
0195: }
0196:
0197: /**
0198: * @ejb.interface-method
0199: * @ejb.transaction type="Required"
0200: */
0201: public void createSynchronizer(URI uri, String name,
0202: String description, String encoding, String binExt)
0203: throws LibresourceSynchronizerException,
0204: LibresourceSecurityException, URINotExistException {
0205: try {
0206: KernelService kernelService = (KernelService) Libresource
0207: .getService(KernelConstants.SERVICE);
0208: SynchronizerResourceLocal synchronizerResourceLocal = SynchronizerResourceUtil
0209: .getLocalHome().create(name, description, encoding);
0210:
0211: if (binExt != null) {
0212: synchronizerResourceLocal.setBinaryExtention(binExt);
0213: } else {
0214: synchronizerResourceLocal
0215: .setBinaryExtention(DEFAULT_BINARY_EXTENTION);
0216: }
0217:
0218: kernelService.bind(synchronizerResourceLocal
0219: .getLibresourceResourceIdentifier(), uri, name);
0220:
0221: // event
0222: LibresourceEvent event = new LibresourceEvent(
0223: uri,
0224: synchronizerResourceLocal
0225: .getLibresourceResourceIdentifier(),
0226: kernelService.getConnectedResource(),
0227: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_CREATE);
0228: Libresource.throwEvent(event);
0229: } catch (LibresourceSecurityException se) {
0230: ctx.setRollbackOnly();
0231: throw se;
0232: } catch (Exception e) {
0233: ctx.setRollbackOnly();
0234: throw new LibresourceSynchronizerException(
0235: "Error in createSynchronizer : " + e.getMessage(),
0236: e);
0237: }
0238: }
0239:
0240: /**
0241: * @ejb.interface-method
0242: * @ejb.transaction type="Required"
0243: */
0244: public void editSynchronizer(URI uri, String name,
0245: String description, String fileEncoding,
0246: String binaryExtention)
0247: throws LibresourceSynchronizerException,
0248: LibresourceSecurityException, URINotExistException {
0249: try {
0250: KernelService kernelService = (KernelService) Libresource
0251: .getService(KernelConstants.SERVICE);
0252: LibresourceResourceIdentifier resourceIdentifier = kernelService
0253: .lookup(uri);
0254:
0255: if (!kernelService.checkSecurity(uri,
0256: KernelConstants.SECURITY_UPDATE)) {
0257: throw new LibresourceSecurityException(uri,
0258: KernelConstants.SECURITY_UPDATE);
0259: }
0260:
0261: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
0262: .findResource(resourceIdentifier,
0263: SynchronizerResourceLocal.class);
0264: synchronizerResourceLocal.setName(name);
0265: synchronizerResourceLocal.setDescription(description);
0266: synchronizerResourceLocal.setFileEncoding(fileEncoding);
0267: synchronizerResourceLocal
0268: .setBinaryExtention(binaryExtention);
0269:
0270: // update node
0271: kernelService.setShortName(uri, name);
0272: kernelService.setUpdateDate(uri, new Date());
0273:
0274: // event
0275: LibresourceEvent event = new LibresourceEvent(
0276: uri,
0277: resourceIdentifier,
0278: kernelService.getConnectedResource(),
0279: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_EDIT);
0280: Libresource.throwEvent(event);
0281:
0282: // indexation
0283: Libresource.index(uri);
0284: } catch (LibresourceSecurityException se) {
0285: ctx.setRollbackOnly();
0286: throw se;
0287: } catch (URINotExistException se) {
0288: ctx.setRollbackOnly();
0289: throw se;
0290: } catch (Exception e) {
0291: ctx.setRollbackOnly();
0292: throw new LibresourceSynchronizerException(
0293: "Error in editSynchronizer : " + e.getMessage(), e);
0294: }
0295: }
0296:
0297: /**
0298: * @ejb.interface-method
0299: * @ejb.transaction type="Required"
0300: */
0301: public void deleteSynchronizer(URI uri)
0302: throws LibresourceSynchronizerException,
0303: LibresourceSecurityException, URINotExistException {
0304: try {
0305: KernelService kernelService = (KernelService) Libresource
0306: .getService(KernelConstants.SERVICE);
0307: LibresourceResourceIdentifier resourceIdentifier = kernelService
0308: .lookup(uri);
0309:
0310: // event
0311: LibresourceEvent event = new LibresourceEvent(
0312: uri,
0313: resourceIdentifier,
0314: kernelService.getConnectedResource(),
0315: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_DELETE);
0316: Libresource.throwEvent(event);
0317:
0318: Libresource.checkType(resourceIdentifier,
0319: SynchronizerResourceLocal.class);
0320: kernelService.deleteURI(uri);
0321: } catch (LibresourceSecurityException se) {
0322: ctx.setRollbackOnly();
0323: throw se;
0324: } catch (URINotExistException se) {
0325: ctx.setRollbackOnly();
0326: throw se;
0327: } catch (Exception e) {
0328: ctx.setRollbackOnly();
0329: throw new LibresourceSynchronizerException(
0330: "Error in deleteSynchronizer : " + e.getMessage(),
0331: e);
0332: }
0333: }
0334:
0335: /**
0336: * @ejb.interface-method
0337: * @ejb.transaction type="Required"
0338: */
0339: public SynchronizerResourceValue getSynchronizer(URI uri)
0340: throws LibresourceSynchronizerException,
0341: LibresourceSecurityException, URINotExistException {
0342: try {
0343: KernelService kernelService = (KernelService) Libresource
0344: .getService(KernelConstants.SERVICE);
0345:
0346: if (!kernelService.checkSecurity(uri,
0347: KernelConstants.SECURITY_READ)) {
0348: throw new LibresourceSecurityException(uri,
0349: KernelConstants.SECURITY_READ);
0350: }
0351:
0352: LibresourceResourceIdentifier resourceIdentifier = kernelService
0353: .lookup(uri);
0354: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
0355: .findResource(resourceIdentifier,
0356: SynchronizerResourceLocal.class);
0357: SynchronizerResourceValue resourceValue = synchronizerResourceLocal
0358: .getSynchronizerResourceValue();
0359: resourceValue.setUri(kernelService.normalizeURI(uri));
0360:
0361: return resourceValue;
0362: } catch (LibresourceSecurityException se) {
0363: throw se;
0364: } catch (URINotExistException se) {
0365: throw se;
0366: } catch (Exception e) {
0367: throw new LibresourceSynchronizerException(
0368: "Error in getSynchronizer : " + e.getMessage(), e);
0369: }
0370: }
0371:
0372: /**
0373: * @ejb.interface-method
0374: * @ejb.transaction type="Required"
0375: */
0376: public SynchronizerResourceValue[] listSynchronizerAt(URI uri)
0377: throws LibresourceSynchronizerException,
0378: LibresourceSecurityException, URINotExistException {
0379: try {
0380: KernelService kernelService = (KernelService) Libresource
0381: .getService(KernelConstants.SERVICE);
0382: LibresourceResourceValue[] pages = kernelService
0383: .listResourcesAt(
0384: uri,
0385: SynchronizerResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
0386: SynchronizerResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
0387: SynchronizerResourceValue[] synchronizerResourceValues = new SynchronizerResourceValue[pages.length];
0388:
0389: for (int i = 0; i < synchronizerResourceValues.length; i++) {
0390: LibresourceResourceIdentifier resourceIdentifier = pages[i]
0391: .getLibresourceResourceIdentifier();
0392: synchronizerResourceValues[i] = ((SynchronizerResourceLocal) Libresource
0393: .findResource(resourceIdentifier))
0394: .getSynchronizerResourceValue();
0395: synchronizerResourceValues[i].setUri(kernelService
0396: .normalizeURI(pages[i].getUri()));
0397: }
0398:
0399: return synchronizerResourceValues;
0400: } catch (LibresourceSecurityException se) {
0401: throw se;
0402: } catch (URINotExistException se) {
0403: throw se;
0404: } catch (Exception e) {
0405: throw new LibresourceSynchronizerException(
0406: "Error in listSynchronizerAt : " + e.getMessage(),
0407: e);
0408: }
0409: }
0410:
0411: /**
0412: * @ejb.interface-method
0413: * @ejb.transaction type="Required"
0414: */
0415: public void createWorkspace(String workspaceId)
0416: throws LibresourceSynchronizerException {
0417: try {
0418: WorkspaceUtil.getLocalHome().findByWorkspaceId(workspaceId);
0419: } catch (FinderException e1) {
0420: // The workspace does not exist...
0421: try {
0422: WorkspaceLocal wsLocal = WorkspaceUtil.getLocalHome()
0423: .create(workspaceId);
0424: } catch (Exception e) {
0425: ctx.setRollbackOnly();
0426: throw new LibresourceSynchronizerException(
0427: "Error in createWorkspace : " + e.getMessage(),
0428: e);
0429: }
0430: } catch (Exception e) {
0431: throw new LibresourceSynchronizerException(
0432: "Error in createWorkspace : " + e.getMessage(), e);
0433: }
0434: }
0435:
0436: /**
0437: * @ejb.interface-method
0438: * @ejb.transaction type="Required"
0439: */
0440: public void removeWorkspace(String workspaceId)
0441: throws LibresourceSynchronizerException {
0442: try {
0443: WorkspaceLocal wsLocal = WorkspaceUtil.getLocalHome()
0444: .findByWorkspaceId(workspaceId);
0445: wsLocal.remove();
0446: } catch (Exception e) {
0447: ctx.setRollbackOnly();
0448: throw new LibresourceSynchronizerException(
0449: "Error in removeWorkspace : " + e.getMessage(), e);
0450: }
0451: }
0452:
0453: /**
0454: * @ejb.interface-method
0455: * @ejb.transaction type="Required"
0456: */
0457: public WorkspaceValue getWorkspaceFromWorkspaceConnection(URI uri)
0458: throws LibresourceSynchronizerException,
0459: LibresourceSecurityException, URINotExistException {
0460: try {
0461: KernelService kernelService = (KernelService) Libresource
0462: .getService(KernelConstants.SERVICE);
0463:
0464: if (!kernelService.checkSecurity(uri,
0465: KernelConstants.SECURITY_READ)) {
0466: throw new LibresourceSecurityException(uri,
0467: KernelConstants.SECURITY_READ);
0468: }
0469:
0470: LibresourceResourceIdentifier resourceIdentifier = kernelService
0471: .lookup(uri);
0472: WsConnectionResourceLocal wscResourceLocal = (WsConnectionResourceLocal) Libresource
0473: .findResource(resourceIdentifier,
0474: WsConnectionResourceLocal.class);
0475:
0476: return wscResourceLocal.getWorkspace().getWorkspaceValue();
0477: } catch (LibresourceSecurityException se) {
0478: throw se;
0479: } catch (URINotExistException se) {
0480: throw se;
0481: } catch (Exception e) {
0482: throw new LibresourceSynchronizerException(
0483: "Error in getWorkspaceFromWorkspaceConnection : "
0484: + e.getMessage(), e);
0485: }
0486: }
0487:
0488: /**
0489: * @ejb.interface-method
0490: * @ejb.transaction type="Required"
0491: */
0492: public WsConnectionResourceValue[] listWorkspaceConnectionsFromWorkspace(
0493: String workspaceId)
0494: throws LibresourceSynchronizerException,
0495: LibresourceSecurityException, URINotExistException {
0496: try {
0497: KernelService kernelService = (KernelService) Libresource
0498: .getService(KernelConstants.SERVICE);
0499: WorkspaceLocal wsLocal = WorkspaceUtil.getLocalHome()
0500: .findByWorkspaceId(workspaceId);
0501: Hashtable resourceAvailableForMe = new Hashtable();
0502: Collection wscList = wsLocal.getConnections();
0503:
0504: for (Iterator i = wscList.iterator(); i.hasNext();) {
0505: try {
0506: WsConnectionResourceLocal resource = (WsConnectionResourceLocal) i
0507: .next();
0508: URI localUri = kernelService.getMyURI(resource
0509: .getLibresourceResourceIdentifier());
0510:
0511: if (kernelService.checkSecurity(localUri,
0512: KernelConstants.SECURITY_READ)) {
0513: resourceAvailableForMe.put(resource.getId(),
0514: localUri);
0515: }
0516: } catch (KernelServiceException e) {
0517: //
0518: }
0519: }
0520:
0521: // construct result set
0522: WsConnectionResourceValue[] replicaResourceValues = new WsConnectionResourceValue[resourceAvailableForMe
0523: .size()];
0524: int index = 0;
0525:
0526: for (Iterator i = wscList.iterator(); i.hasNext();) {
0527: WsConnectionResourceLocal resource = (WsConnectionResourceLocal) i
0528: .next();
0529: WsConnectionResourceValue value = resource
0530: .getWsConnectionResourceValue();
0531:
0532: if (resourceAvailableForMe.get(value.getId()) != null) {
0533: replicaResourceValues[index] = value;
0534: replicaResourceValues[index]
0535: .setUri((URI) resourceAvailableForMe
0536: .get(value.getId()));
0537: index++;
0538: }
0539: }
0540:
0541: return replicaResourceValues;
0542: } catch (LibresourceSecurityException se) {
0543: throw se;
0544: } catch (URINotExistException se) {
0545: throw se;
0546: } catch (Exception e) {
0547: throw new LibresourceSynchronizerException(
0548: "Error in listWorkspaceConnectionsFromWorkspace : "
0549: + e.getMessage(), e);
0550: }
0551: }
0552:
0553: /**
0554: * @ejb.interface-method
0555: * @ejb.transaction type="Required"
0556: */
0557: public void updateWorkspaceConnections(String workspaceId,
0558: String[] queueIds) throws LibresourceSynchronizerException {
0559: try {
0560: WorkspaceLocal wsLocal = WorkspaceUtil.getLocalHome()
0561: .findByWorkspaceId(workspaceId);
0562: Vector connections = new Vector();
0563:
0564: for (int i = 0; i < queueIds.length; i++) {
0565: connections.add(queueIds[i]);
0566: }
0567:
0568: wsLocal.setGlobalConnectedQueue(connections);
0569: } catch (Exception e) {
0570: ctx.setRollbackOnly();
0571: throw new LibresourceSynchronizerException(
0572: "Error in updateWorkspaceConnections : "
0573: + e.getMessage(), e);
0574: }
0575: }
0576:
0577: /**
0578: * @ejb.interface-method
0579: * @ejb.transaction type="Required"
0580: */
0581: public String createWorkspaceConnection(URI uri, String wsid,
0582: String name, String wsPath)
0583: throws LibresourceSynchronizerException,
0584: LibresourceSecurityException, URINotExistException {
0585: try {
0586: KernelService kernelService = (KernelService) Libresource
0587: .getService(KernelConstants.SERVICE);
0588: LibresourceCoreService coreService = (LibresourceCoreService) Libresource
0589: .getService(CoreConstants.SERVICE);
0590:
0591: // Check security
0592: if (!kernelService.checkSecurity(uri, SO6_CREATE_WORKSPACE)) {
0593: throw new LibresourceSecurityException(uri,
0594: SO6_CREATE_WORKSPACE);
0595: }
0596:
0597: // Synchronizer
0598: LibresourceResourceIdentifier resourceIdentifier = kernelService
0599: .lookup(uri);
0600: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
0601: .findResource(resourceIdentifier,
0602: SynchronizerResourceLocal.class);
0603:
0604: // Workspace
0605: WorkspaceLocal wsLocal = null;
0606:
0607: try {
0608: wsLocal = WorkspaceUtil.getLocalHome()
0609: .findByWorkspaceId(wsid);
0610: } catch (FinderException e) {
0611: // The workspace come from another plateform
0612: wsLocal = WorkspaceUtil.getLocalHome().create(wsid);
0613: }
0614:
0615: // WsConnection
0616: WsConnectionResourceLocal wsConnectionResourceLocal = WsConnectionResourceUtil
0617: .getLocalHome().create(name, wsPath, wsLocal,
0618: synchronizerResourceLocal);
0619: wsConnectionResourceLocal.setManager(kernelService
0620: .getConnectedResource().getPath());
0621:
0622: // Bind replica in naming
0623: URI replicaURI = new URI(uri.toString() + "/"
0624: + wsConnectionResourceLocal.getId());
0625:
0626: // System.out.println("create uri: " + replicaURI);
0627: kernelService.systemCreateURI(replicaURI);
0628: kernelService.systemBind(wsConnectionResourceLocal
0629: .getLibresourceResourceIdentifier(), replicaURI,
0630: name);
0631:
0632: String[] rights = new String[3];
0633: rights[0] = KernelConstants.SECURITY_READ;
0634: rights[1] = KernelConstants.SECURITY_UPDATE;
0635: rights[2] = KernelConstants.SECURITY_DELETE;
0636: kernelService.systemCreateAcl(replicaURI, kernelService
0637: .getConnectedResource(), rights);
0638: kernelService.systemCreateAcl(replicaURI, kernelService
0639: .getOwner(uri), rights);
0640: kernelService.systemChown(replicaURI, kernelService
0641: .getOwner(uri), true);
0642:
0643: // update node
0644: kernelService.setUpdateDate(uri, new Date());
0645:
0646: // event
0647: LibresourceEvent event = new LibresourceEvent(
0648: uri,
0649: resourceIdentifier,
0650: kernelService.getConnectedResource(),
0651: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_CREATE);
0652: Libresource.throwEvent(event);
0653:
0654: // create event filter
0655: coreService
0656: .addEventFilter(
0657: "Watch commit to synchronizer "
0658: + uri.getPath(),
0659: kernelService.getConnectedResource(),
0660: kernelService.normalizeAbsoluteURIPath(uri),
0661: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_ADD_PATCH,
0662: "*", "mail");
0663:
0664: return replicaURI.toString();
0665: } catch (LibresourceSecurityException se) {
0666: ctx.setRollbackOnly();
0667: throw se;
0668: } catch (Exception e) {
0669: ctx.setRollbackOnly();
0670: throw new LibresourceSynchronizerException(
0671: "Error in createWorkspaceConnection : "
0672: + e.getMessage(), e);
0673: }
0674: }
0675:
0676: /**
0677: * @ejb.interface-method
0678: * @ejb.transaction type="Required"
0679: */
0680: public void editWorkspaceConnection(URI uri, String name,
0681: String wsPath, String managerUri)
0682: throws LibresourceSynchronizerException,
0683: LibresourceSecurityException, URINotExistException {
0684: try {
0685: KernelService kernelService = (KernelService) Libresource
0686: .getService(KernelConstants.SERVICE);
0687: LibresourceResourceIdentifier resourceIdentifier = kernelService
0688: .lookup(uri);
0689:
0690: if (!kernelService.checkSecurity(uri,
0691: KernelConstants.SECURITY_UPDATE)) {
0692: throw new LibresourceSecurityException(uri,
0693: KernelConstants.SECURITY_UPDATE);
0694: }
0695:
0696: WsConnectionResourceLocal replicaResourceLocal = (WsConnectionResourceLocal) Libresource
0697: .findResource(resourceIdentifier,
0698: WsConnectionResourceLocal.class);
0699: replicaResourceLocal.setName(name);
0700: kernelService.setShortName(uri, name);
0701: replicaResourceLocal.setWsPath(wsPath);
0702: replicaResourceLocal.setManager(new URI(managerUri)
0703: .getPath());
0704:
0705: // update node
0706: kernelService.setShortName(uri, name);
0707: kernelService.setUpdateDate(uri, new Date());
0708:
0709: // event
0710: LibresourceEvent event = new LibresourceEvent(
0711: uri,
0712: resourceIdentifier,
0713: kernelService.getConnectedResource(),
0714: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_EDIT);
0715: Libresource.throwEvent(event);
0716:
0717: // indexation
0718: Libresource.index(uri);
0719: } catch (LibresourceSecurityException se) {
0720: ctx.setRollbackOnly();
0721: throw se;
0722: } catch (URINotExistException se) {
0723: ctx.setRollbackOnly();
0724: throw se;
0725: } catch (Exception e) {
0726: ctx.setRollbackOnly();
0727: throw new LibresourceSynchronizerException(
0728: "Error in editWorkspaceConnection : "
0729: + e.getMessage(), e);
0730: }
0731: }
0732:
0733: /**
0734: * @ejb.interface-method
0735: * @ejb.transaction type="Required"
0736: */
0737: public void updateWorkspaceConnectionTicket(URI uri,
0738: long newLastTicket)
0739: throws LibresourceSynchronizerException,
0740: LibresourceSecurityException, URINotExistException {
0741: try {
0742: KernelService kernelService = (KernelService) Libresource
0743: .getService(KernelConstants.SERVICE);
0744: LibresourceResourceIdentifier resourceIdentifier = kernelService
0745: .lookup(uri);
0746:
0747: if (!kernelService.checkSecurity(uri,
0748: KernelConstants.SECURITY_UPDATE)) {
0749: throw new LibresourceSecurityException(uri,
0750: KernelConstants.SECURITY_UPDATE);
0751: }
0752:
0753: WsConnectionResourceLocal wsConnectionResourceLocal = (WsConnectionResourceLocal) Libresource
0754: .findResource(resourceIdentifier,
0755: WsConnectionResourceLocal.class);
0756: wsConnectionResourceLocal.setLastTicket(newLastTicket);
0757: wsConnectionResourceLocal.setLastSynchro(new Date());
0758:
0759: // update node
0760: kernelService.setUpdateDate(uri, new Date());
0761:
0762: // event
0763: LibresourceEvent event = new LibresourceEvent(
0764: uri,
0765: resourceIdentifier,
0766: kernelService.getConnectedResource(),
0767: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_UPDATELASTTICKET);
0768: Libresource.throwEvent(event);
0769:
0770: // indexation
0771: Libresource.index(uri);
0772: } catch (LibresourceSecurityException se) {
0773: ctx.setRollbackOnly();
0774: throw se;
0775: } catch (URINotExistException se) {
0776: ctx.setRollbackOnly();
0777: throw se;
0778: } catch (Exception e) {
0779: ctx.setRollbackOnly();
0780: throw new LibresourceSynchronizerException(
0781: "Error in updateWorkspaceConnectionTicket : "
0782: + e.getMessage(), e);
0783: }
0784: }
0785:
0786: /**
0787: * @ejb.interface-method
0788: * @ejb.transaction type="Required"
0789: */
0790: public void updateWorkspaceConnectionTicket(URI uri,
0791: long newLastTicket, Date lastSynchro)
0792: throws LibresourceSynchronizerException,
0793: LibresourceSecurityException, URINotExistException {
0794: try {
0795: KernelService kernelService = (KernelService) Libresource
0796: .getService(KernelConstants.SERVICE);
0797: LibresourceResourceIdentifier resourceIdentifier = kernelService
0798: .lookup(uri);
0799:
0800: if (!kernelService.checkSecurity(uri,
0801: KernelConstants.SECURITY_UPDATE)) {
0802: throw new LibresourceSecurityException(uri,
0803: KernelConstants.SECURITY_UPDATE);
0804: }
0805:
0806: WsConnectionResourceLocal wsConnectionResourceLocal = (WsConnectionResourceLocal) Libresource
0807: .findResource(resourceIdentifier,
0808: WsConnectionResourceLocal.class);
0809: wsConnectionResourceLocal.setLastTicket(newLastTicket);
0810: wsConnectionResourceLocal.setLastSynchro(lastSynchro);
0811:
0812: // update node
0813: kernelService.setUpdateDate(uri, new Date());
0814:
0815: // event
0816: LibresourceEvent event = new LibresourceEvent(
0817: uri,
0818: resourceIdentifier,
0819: kernelService.getConnectedResource(),
0820: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_UPDATELASTTICKET);
0821: Libresource.throwEvent(event);
0822:
0823: // indexation
0824: Libresource.index(uri);
0825: } catch (LibresourceSecurityException se) {
0826: ctx.setRollbackOnly();
0827: throw se;
0828: } catch (URINotExistException se) {
0829: ctx.setRollbackOnly();
0830: throw se;
0831: } catch (Exception e) {
0832: ctx.setRollbackOnly();
0833: throw new LibresourceSynchronizerException(
0834: "Error in updateWorkspaceConnectionTicket : "
0835: + e.getMessage(), e);
0836: }
0837: }
0838:
0839: /**
0840: * @ejb.interface-method
0841: * @ejb.transaction type="Required"
0842: */
0843: public void deleteWorkspaceConnection(URI uri)
0844: throws LibresourceSynchronizerException,
0845: LibresourceSecurityException, URINotExistException {
0846: try {
0847: KernelService kernelService = (KernelService) Libresource
0848: .getService(KernelConstants.SERVICE);
0849: LibresourceResourceIdentifier resourceIdentifier = kernelService
0850: .lookup(uri);
0851:
0852: // event
0853: LibresourceEvent event = new LibresourceEvent(
0854: uri,
0855: resourceIdentifier,
0856: kernelService.getConnectedResource(),
0857: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_DELETE);
0858: Libresource.throwEvent(event);
0859:
0860: Libresource.checkType(resourceIdentifier,
0861: WsConnectionResourceLocal.class);
0862:
0863: //
0864: WsConnectionResourceLocal replicaResourceLocal = (WsConnectionResourceLocal) Libresource
0865: .findResource(resourceIdentifier,
0866: WsConnectionResourceLocal.class);
0867: replicaResourceLocal.getSynchronizer().getWsConnections()
0868: .remove(replicaResourceLocal);
0869: kernelService.deleteURI(uri);
0870: } catch (LibresourceSecurityException se) {
0871: ctx.setRollbackOnly();
0872: throw se;
0873: } catch (URINotExistException se) {
0874: ctx.setRollbackOnly();
0875: throw se;
0876: } catch (Exception e) {
0877: ctx.setRollbackOnly();
0878: throw new LibresourceSynchronizerException(
0879: "Error in deleteWorkspaceConnection : "
0880: + e.getMessage(), e);
0881: }
0882: }
0883:
0884: /**
0885: * @ejb.interface-method
0886: * @ejb.transaction type="Required"
0887: */
0888: public void deleteWorkspaceConnection(URI synchronizerUri,
0889: String workspaceId)
0890: throws LibresourceSynchronizerException,
0891: LibresourceSecurityException, URINotExistException {
0892: try {
0893: KernelService kernelService = (KernelService) Libresource
0894: .getService(KernelConstants.SERVICE);
0895: LibresourceResourceIdentifier resourceIdentifier = kernelService
0896: .lookup(synchronizerUri);
0897:
0898: // event
0899: LibresourceEvent event = new LibresourceEvent(
0900: synchronizerUri,
0901: resourceIdentifier,
0902: kernelService.getConnectedResource(),
0903: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_DELETE);
0904: Libresource.throwEvent(event);
0905:
0906: Libresource.checkType(resourceIdentifier,
0907: SynchronizerResourceLocal.class);
0908:
0909: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
0910: .findResource(resourceIdentifier,
0911: SynchronizerResourceLocal.class);
0912:
0913: //
0914: Collection c = synchronizerResourceLocal.getWsConnections();
0915:
0916: for (Iterator i = c.iterator(); i.hasNext();) {
0917: WsConnectionResourceLocal wsc = (WsConnectionResourceLocal) i
0918: .next();
0919:
0920: if (wsc.getWorkspace().getWorkspaceId().equals(
0921: workspaceId)) {
0922: URI wsConnectionURI = kernelService.getMyURI(wsc
0923: .getLibresourceResourceIdentifier());
0924: kernelService.deleteURI(wsConnectionURI);
0925: wsc.remove();
0926:
0927: return;
0928: }
0929: }
0930: } catch (LibresourceSecurityException se) {
0931: ctx.setRollbackOnly();
0932: throw se;
0933: } catch (URINotExistException se) {
0934: ctx.setRollbackOnly();
0935: throw se;
0936: } catch (Exception e) {
0937: ctx.setRollbackOnly();
0938: throw new LibresourceSynchronizerException(
0939: "Error in deleteWorkspaceConnection : "
0940: + e.getMessage(), e);
0941: }
0942: }
0943:
0944: /**
0945: * @ejb.interface-method
0946: * @ejb.transaction type="Required"
0947: */
0948: public WsConnectionResourceValue getWorkspaceConnection(URI uri)
0949: throws LibresourceSynchronizerException,
0950: LibresourceSecurityException, URINotExistException {
0951: try {
0952: KernelService kernelService = (KernelService) Libresource
0953: .getService(KernelConstants.SERVICE);
0954: LibresourceResourceIdentifier resourceIdentifier = kernelService
0955: .lookup(uri);
0956: WsConnectionResourceLocal workspaceConnectionResourceLocal = (WsConnectionResourceLocal) Libresource
0957: .findResource(resourceIdentifier,
0958: WsConnectionResourceLocal.class);
0959: WsConnectionResourceValue resourceValue = workspaceConnectionResourceLocal
0960: .getWsConnectionResourceValue();
0961: resourceValue.setUri(kernelService.normalizeURI(uri));
0962:
0963: return resourceValue;
0964: } catch (LibresourceSecurityException se) {
0965: throw se;
0966: } catch (URINotExistException se) {
0967: throw se;
0968: } catch (Exception e) {
0969: throw new LibresourceSynchronizerException(
0970: "Error in getWorkspaceConnection : "
0971: + e.getMessage(), e);
0972: }
0973: }
0974:
0975: /**
0976: * @ejb.interface-method
0977: * @ejb.transaction type="Required"
0978: */
0979: public Vector listManagerWsConnection(String manager)
0980: throws LibresourceSynchronizerException,
0981: LibresourceSecurityException, URINotExistException {
0982: try {
0983: KernelService kernelService = (KernelService) Libresource
0984: .getService(KernelConstants.SERVICE);
0985: Collection c = WsConnectionResourceUtil.getLocalHome()
0986: .findByManager(manager);
0987: Vector res = new Vector();
0988:
0989: for (Iterator iter = c.iterator(); iter.hasNext();) {
0990: WsConnectionResourceLocal wsc = (WsConnectionResourceLocal) iter
0991: .next();
0992: Object[] entry = new Object[4];
0993:
0994: try {
0995: entry[0] = (kernelService.getMyURI(wsc
0996: .getLibresourceResourceIdentifier()));
0997: entry[1] = wsc.getName();
0998: entry[2] = wsc.getSynchronizer().getName();
0999: entry[3] = new Boolean(wsc.getLastTicket() < wsc
1000: .getSynchronizer().getLastTicket());
1001: res.add(entry);
1002: } catch (Exception e) {
1003: // lazy
1004: }
1005: }
1006:
1007: return res;
1008: } catch (Exception e) {
1009: throw new LibresourceSynchronizerException(
1010: "Error in listManagerWsConnection : "
1011: + e.getMessage(), e);
1012: }
1013: }
1014:
1015: /**
1016: * @ejb.interface-method
1017: * @ejb.transaction type="Required"
1018: */
1019: public WsConnectionResourceValue[] listWorkspaceConnectionsAt(
1020: URI uri) throws LibresourceSynchronizerException,
1021: LibresourceSecurityException, URINotExistException {
1022: try {
1023: KernelService kernelService = (KernelService) Libresource
1024: .getService(KernelConstants.SERVICE);
1025: LibresourceResourceValue[] pages = kernelService
1026: .listResourcesAt(
1027: uri,
1028: WsConnectionResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
1029: WsConnectionResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
1030: WsConnectionResourceValue[] workspaceConnectionResourceValues = new WsConnectionResourceValue[pages.length];
1031:
1032: for (int i = 0; i < workspaceConnectionResourceValues.length; i++) {
1033: LibresourceResourceIdentifier resourceIdentifier = pages[i]
1034: .getLibresourceResourceIdentifier();
1035: workspaceConnectionResourceValues[i] = ((WsConnectionResourceLocal) Libresource
1036: .findResource(resourceIdentifier))
1037: .getWsConnectionResourceValue();
1038: workspaceConnectionResourceValues[i]
1039: .setUri(kernelService.normalizeURI(pages[i]
1040: .getUri()));
1041: }
1042:
1043: return workspaceConnectionResourceValues;
1044: } catch (LibresourceSecurityException se) {
1045: throw se;
1046: } catch (URINotExistException se) {
1047: throw se;
1048: } catch (Exception e) {
1049: throw new LibresourceSynchronizerException(
1050: "Error in listWorkspaceConnectionsAt : "
1051: + e.getMessage(), e);
1052: }
1053: }
1054:
1055: /**
1056: * @ejb.interface-method
1057: * @ejb.transaction type="Required"
1058: */
1059: public WsConnectionResourceValue[] listSynchronizerConnections(
1060: URI uri) throws LibresourceSynchronizerException,
1061: LibresourceSecurityException {
1062: try {
1063: KernelService kernelService = (KernelService) Libresource
1064: .getService(KernelConstants.SERVICE);
1065:
1066: if (!kernelService.checkSecurity(uri,
1067: KernelConstants.SECURITY_READ)) {
1068: throw new LibresourceSecurityException(uri,
1069: KernelConstants.SECURITY_READ);
1070: }
1071:
1072: Hashtable resourceAvailableForMe = new Hashtable();
1073: LibresourceResourceIdentifier resourceIdentifier = kernelService
1074: .lookup(uri);
1075: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
1076: .findResource(resourceIdentifier,
1077: SynchronizerResourceLocal.class);
1078: Collection replicaList = synchronizerResourceLocal
1079: .getWsConnections();
1080:
1081: // remove unbinded replica if needed
1082: for (Iterator i = replicaList.iterator(); i.hasNext();) {
1083: WsConnectionResourceLocal resource = (WsConnectionResourceLocal) i
1084: .next();
1085:
1086: try {
1087: URI localUri = kernelService.getMyURI(resource
1088: .getLibresourceResourceIdentifier());
1089:
1090: if (kernelService.checkSecurity(localUri,
1091: KernelConstants.SECURITY_READ)) {
1092: resourceAvailableForMe.put(resource.getId(),
1093: localUri);
1094: }
1095: } catch (Exception e) {
1096: try {
1097: replicaList.remove(resource);
1098: } catch (RuntimeException e1) {
1099: }
1100: }
1101: }
1102:
1103: // construct result set
1104: WsConnectionResourceValue[] replicaResourceValues = new WsConnectionResourceValue[resourceAvailableForMe
1105: .size()];
1106: int index = 0;
1107:
1108: for (Iterator i = replicaList.iterator(); i.hasNext();) {
1109: WsConnectionResourceLocal resource = (WsConnectionResourceLocal) i
1110: .next();
1111: WsConnectionResourceValue value = resource
1112: .getWsConnectionResourceValue();
1113:
1114: if (resourceAvailableForMe.get(value.getId()) != null) {
1115: replicaResourceValues[index] = value;
1116: replicaResourceValues[index]
1117: .setUri((URI) resourceAvailableForMe
1118: .get(value.getId()));
1119: index++;
1120: }
1121: }
1122:
1123: return replicaResourceValues;
1124: } catch (LibresourceSecurityException se) {
1125: throw se;
1126: } catch (Exception e) {
1127: throw new LibresourceSynchronizerException(
1128: "Error in listSynchronizerConnections : "
1129: + e.getMessage(), e);
1130: }
1131: }
1132:
1133: /**
1134: * @ejb.interface-method
1135: * @ejb.transaction type="Required"
1136: */
1137: public SynchronizerResourceValue getWorkspaceConnectionSynchronizer(
1138: URI uri) throws LibresourceSynchronizerException,
1139: LibresourceSecurityException, URINotExistException {
1140: try {
1141: KernelService kernelService = (KernelService) Libresource
1142: .getService(KernelConstants.SERVICE);
1143: LibresourceResourceIdentifier resourceIdentifier = kernelService
1144: .lookup(uri);
1145: WsConnectionResourceLocal replicaResourceLocal = (WsConnectionResourceLocal) Libresource
1146: .findResource(resourceIdentifier,
1147: WsConnectionResourceLocal.class);
1148: SynchronizerResourceValue synchronizerResourceValue = replicaResourceLocal
1149: .getSynchronizer().getSynchronizerResourceValue();
1150: synchronizerResourceValue.setUri(kernelService
1151: .getMyURI(replicaResourceLocal.getSynchronizer()
1152: .getLibresourceResourceIdentifier()));
1153:
1154: if (!kernelService.checkSecurity(synchronizerResourceValue
1155: .getUri(), KernelConstants.SECURITY_READ)) {
1156: throw new LibresourceSecurityException(
1157: synchronizerResourceValue.getUri(),
1158: KernelConstants.SECURITY_READ);
1159: }
1160:
1161: return synchronizerResourceValue;
1162: } catch (LibresourceSecurityException se) {
1163: throw se;
1164: } catch (URINotExistException se) {
1165: throw se;
1166: } catch (Exception e) {
1167: throw new LibresourceSynchronizerException(
1168: "Error in getWorkspaceConnectionSynchronizer : "
1169: + e.getMessage(), e);
1170: }
1171: }
1172:
1173: /**
1174: * @ejb.interface-method
1175: * @ejb.transaction type="Required"
1176: */
1177: public FileData getNetworkFromWorkspace(String workspaceId)
1178: throws LibresourceSynchronizerException,
1179: LibresourceSecurityException {
1180: try {
1181: WorkspaceLocal wsLocal = WorkspaceUtil.getLocalHome()
1182: .findByWorkspaceId(workspaceId);
1183: ArrayList wsConnectionIds = new ArrayList();
1184:
1185: File dir = new File(getDistributedFileSystem()
1186: + File.separator + "so6Net");
1187: dir.mkdirs();
1188:
1189: File tmpFile = File.createTempFile("so6Network", null, dir);
1190: FileWriter fw = new FileWriter(tmpFile);
1191:
1192: OutputFormat of = new OutputFormat("", "iso-8859-1", false);
1193: XMLSerializer xmlSerializer = new XMLSerializer(fw, of);
1194: xmlSerializer.startDocument();
1195: dataflowBuilder(xmlSerializer, wsConnectionIds, wsLocal
1196: .getWorkspaceValue());
1197: xmlSerializer.endDocument();
1198:
1199: return new FileDataImpl(tmpFile);
1200: } catch (Exception e) {
1201: throw new LibresourceSynchronizerException(
1202: "Error in getNetworkFromWorkspace : "
1203: + e.getMessage(), e);
1204: }
1205: }
1206:
1207: /**
1208: * @ejb.interface-method
1209: * @ejb.transaction type="Required"
1210: */
1211: public FileData getNetworkFromQueue(URI queueUri)
1212: throws LibresourceSynchronizerException,
1213: LibresourceSecurityException, URINotExistException {
1214: try {
1215: KernelService kernelService = (KernelService) Libresource
1216: .getService(KernelConstants.SERVICE);
1217: SynchronizerResourceValue queue = getSynchronizer(queueUri);
1218: ArrayList wsConnectionIds = new ArrayList();
1219:
1220: File dir = new File(getDistributedFileSystem()
1221: + File.separator + "so6Net");
1222: dir.mkdirs();
1223:
1224: File tmpFile = File.createTempFile("so6Network", null, dir);
1225: FileWriter fw = new FileWriter(tmpFile);
1226:
1227: OutputFormat of = new OutputFormat("", "iso-8859-1", false);
1228: XMLSerializer xmlSerializer = new XMLSerializer(fw, of);
1229: xmlSerializer.startDocument();
1230: dataflowBuilder(xmlSerializer, wsConnectionIds, queue);
1231: xmlSerializer.endDocument();
1232:
1233: return new FileDataImpl(tmpFile);
1234: } catch (Exception e) {
1235: throw new LibresourceSynchronizerException(
1236: "Error in getNetworkFromQueue : " + e.getMessage(),
1237: e);
1238: }
1239: }
1240:
1241: /**
1242: * @ejb.interface-method
1243: * @ejb.transaction type="Required"
1244: */
1245: public void dataflowBuilder(XMLSerializer out,
1246: Collection wsConnectionIds, SynchronizerResourceValue value)
1247: throws IOException, LibresourceSynchronizerException,
1248: LibresourceSecurityException, URINotExistException,
1249: SAXException {
1250: // Dump a queue
1251: AttributeListImpl al = new AttributeListImpl();
1252: al.addAttribute("label", null, value.getName() + " "
1253: + Long.toString(value.getLastTicket()));
1254: al.addAttribute("LastTicket", null, Long.toString(value
1255: .getLastTicket()));
1256: al.addAttribute("id", null, value.getId());
1257: al.addAttribute("Name", null, value.getName());
1258: al.addAttribute("BinExt", null, value.getBinaryExtention());
1259: al.addAttribute("Description", null, value.getDescription());
1260: al.addAttribute("uri", null, value.getUri().toString());
1261: out.startElement("Queue", al);
1262:
1263: //
1264: WsConnectionResourceValue[] connections = listSynchronizerConnections(value
1265: .getUri());
1266:
1267: for (int i = 0; i < connections.length; i++) {
1268: dataflowBuilder(out, wsConnectionIds, connections[i], false);
1269: }
1270:
1271: out.endElement("Queue");
1272: }
1273:
1274: /**
1275: * @ejb.interface-method
1276: * @ejb.transaction type="Required"
1277: */
1278: public void dataflowBuilder(XMLSerializer out,
1279: Collection wsConnectionIds, WorkspaceValue value)
1280: throws IOException, LibresourceSynchronizerException,
1281: LibresourceSecurityException, URINotExistException,
1282: SAXException {
1283: // Dump workspace
1284: AttributeListImpl al = new AttributeListImpl();
1285: al.addAttribute("id", null, value.getWorkspaceId());
1286: out.startElement("Ws", al);
1287:
1288: WsConnectionResourceValue[] connections = listWorkspaceConnectionsFromWorkspace(value
1289: .getWorkspaceId());
1290:
1291: for (int i = 0; i < connections.length; i++) {
1292: dataflowBuilder(out, wsConnectionIds, connections[i], true);
1293: }
1294:
1295: out.endElement("Ws");
1296: }
1297:
1298: /**
1299: * @ejb.interface-method
1300: * @ejb.transaction type="Required"
1301: */
1302: public void dataflowBuilder(XMLSerializer out,
1303: Collection wsConnectionIds,
1304: WsConnectionResourceValue value, boolean isWsToQueue)
1305: throws IOException, LibresourceSynchronizerException,
1306: LibresourceSecurityException, URINotExistException,
1307: SAXException {
1308: // Dump connections
1309: if (!wsConnectionIds.contains(value.getId())) {
1310: wsConnectionIds.add(value.getId());
1311:
1312: AttributeListImpl al = new AttributeListImpl();
1313: al.addAttribute("label", null, Long.toString(value
1314: .getLastTicket()));
1315:
1316: if (value.getLastSynchro() != null) {
1317: al.addAttribute("LastSynchro", null, value
1318: .getLastSynchro().toString());
1319: }
1320:
1321: al.addAttribute("Manager", null, value.getManager());
1322: al.addAttribute("uri", null, value.getUri().toString());
1323: al.addAttribute("id", null, value.getId());
1324: al.addAttribute("ConnectionName", null, value.getName());
1325: al.addAttribute("WscPath", null, value.getWsPath());
1326:
1327: out.startElement("WsConnection", al);
1328:
1329: // propagate in the right direction
1330: if (isWsToQueue) {
1331: dataflowBuilder(out, wsConnectionIds,
1332: getWorkspaceConnectionSynchronizer(value
1333: .getUri()));
1334: } else {
1335: dataflowBuilder(out, wsConnectionIds,
1336: getWorkspaceFromWorkspaceConnection(value
1337: .getUri()));
1338: }
1339:
1340: out.endElement("WsConnection");
1341: }
1342: }
1343:
1344: /**
1345: * @ejb.interface-method
1346: * @ejb.transaction type="Required"
1347: */
1348: public PatchBean getSynchronizerPatchValue(URI uri,
1349: long fromTicket, long toTicket)
1350: throws LibresourceSynchronizerException,
1351: LibresourceSecurityException, URINotExistException {
1352: // SQL Object
1353: Connection con = null;
1354: Statement stmt = null;
1355: ResultSet rs = null;
1356:
1357: try {
1358: KernelService kernelService = (KernelService) Libresource
1359: .getService(KernelConstants.SERVICE);
1360:
1361: if (!(kernelService.checkSecurity(uri,
1362: KernelConstants.SECURITY_READ))) {
1363: throw new LibresourceSecurityException(uri,
1364: KernelConstants.SECURITY_READ);
1365: }
1366:
1367: //
1368: SynchronizerResourceValue synchronizerValue = getSynchronizer(uri);
1369: String synchronizerId = synchronizerValue.getId();
1370:
1371: // Find pacth
1372: con = getConnection();
1373: stmt = con.createStatement();
1374:
1375: String query = "SELECT comment_,time_,wsName_,xmlPatchSize_,tagName_,tagged_,changeLog_ FROM ls_patch_"
1376: + synchronizerId
1377: + " WHERE builtPatch = false AND fromTicket_ = "
1378: + fromTicket + " AND toTicket_ = " + toTicket;
1379:
1380: try {
1381: rs = stmt.executeQuery(query);
1382: } catch (SQLException e1) {
1383: // update the table...
1384: String query1 = "ALTER TABLE ls_patch_"
1385: + synchronizerId + " ADD tagName_ TEXT";
1386: String query2 = "ALTER TABLE ls_patch_"
1387: + synchronizerId + " ADD tagged_ Boolean";
1388: String query3 = "ALTER TABLE ls_patch_"
1389: + synchronizerId + " ADD changeLog_ TEXT";
1390: String query4 = "UPDATE ls_patch_" + synchronizerId
1391: + " SET tagName_ = ''";
1392: String query5 = "UPDATE ls_patch_" + synchronizerId
1393: + " SET changeLog_ = ''";
1394: stmt.execute(query1);
1395: stmt.execute(query2);
1396: stmt.execute(query3);
1397: stmt.execute(query4);
1398: stmt.execute(query5);
1399: rs = stmt.executeQuery(query);
1400: }
1401:
1402: if (rs.next()) {
1403: PatchBean patchInfo = new PatchBean();
1404: patchInfo.setFromTicket(fromTicket);
1405: patchInfo.setToTicket(toTicket);
1406: patchInfo.setComment(rs.getString("comment_"));
1407: patchInfo.setCreationDate(rs.getTimestamp("time_"));
1408: patchInfo.setWsName(rs.getString("wsName_"));
1409: patchInfo.setPatchSize(rs.getLong("xmlPatchSize_"));
1410: patchInfo.setTagName(rs.getString("tagName_"));
1411: patchInfo.setFiles(rs.getString("changeLog_"));
1412: patchInfo.setTagged(rs.getBoolean("tagged_"));
1413:
1414: //
1415: return patchInfo;
1416: }
1417:
1418: return null;
1419: } catch (LibresourceSecurityException se) {
1420: throw se;
1421: } catch (URINotExistException se) {
1422: throw se;
1423: } catch (Exception e) {
1424: throw new LibresourceSynchronizerException(
1425: "Error in getSynchronizerPatchValue : "
1426: + e.getMessage(), e);
1427: } finally {
1428: // Close all db resource
1429: if (stmt != null) {
1430: try {
1431: stmt.close();
1432: } catch (SQLException e) {
1433: }
1434: }
1435:
1436: if (rs != null) {
1437: try {
1438: rs.close();
1439: } catch (SQLException e) {
1440: }
1441: }
1442:
1443: if (con != null) {
1444: try {
1445: con.close();
1446: } catch (SQLException e) {
1447: }
1448: }
1449: }
1450: }
1451:
1452: /**
1453: * @ejb.interface-method
1454: * @ejb.transaction type="Required"
1455: *
1456: * @param compressedPatch
1457: * <ul>
1458: * <li>-1 for all kind of patch</li>
1459: * <li>0 for user patch</li>
1460: * <li>1 for generated compressed patch</li>
1461: * </ul>
1462: */
1463: public PatchBean[] listSynchronizerPatch(URI uri,
1464: int compressedPatch)
1465: throws LibresourceSynchronizerException,
1466: LibresourceSecurityException, URINotExistException {
1467: // SQL Object
1468: Connection con = null;
1469: Statement stmt = null;
1470: ResultSet rs = null;
1471:
1472: try {
1473: KernelService kernelService = (KernelService) Libresource
1474: .getService(KernelConstants.SERVICE);
1475:
1476: if (!(kernelService.checkSecurity(uri,
1477: KernelConstants.SECURITY_READ))) {
1478: throw new LibresourceSecurityException(uri,
1479: KernelConstants.SECURITY_READ);
1480: }
1481:
1482: //
1483: SynchronizerResourceValue synchronizerValue = getSynchronizer(uri);
1484: String synchronizerId = synchronizerValue.getId();
1485:
1486: // Find patch
1487: con = getConnection();
1488: stmt = con.createStatement();
1489:
1490: String query = "SELECT fromTicket_,toTicket_,comment_,time_,wsName_,xmlPatchSize_,tagName_,tagged_,changeLog_ FROM ls_patch_"
1491: + synchronizerId;
1492:
1493: if (compressedPatch == 0) {
1494: query += " WHERE builtPatch = false ";
1495: }
1496:
1497: if (compressedPatch == 1) {
1498: query += " WHERE fromTicket_ = 1 ";
1499: }
1500:
1501: query += " ORDER BY toTicket_ DESC ";
1502:
1503: try {
1504: rs = stmt.executeQuery(query);
1505: } catch (SQLException e1) {
1506: // update the table...
1507: String query1 = "ALTER TABLE ls_patch_"
1508: + synchronizerId + " ADD tagName_ TEXT";
1509: String query2 = "ALTER TABLE ls_patch_"
1510: + synchronizerId + " ADD tagged_ Boolean";
1511: String query3 = "ALTER TABLE ls_patch_"
1512: + synchronizerId + " ADD changeLog_ TEXT";
1513: String query4 = "UPDATE ls_patch_" + synchronizerId
1514: + " SET tagName_ = ''";
1515: String query5 = "UPDATE ls_patch_" + synchronizerId
1516: + " SET changeLog_ = ''";
1517: stmt.execute(query1);
1518: stmt.execute(query2);
1519: stmt.execute(query3);
1520: stmt.execute(query4);
1521: stmt.execute(query5);
1522: rs = stmt.executeQuery(query);
1523: }
1524:
1525: ArrayList tmp = new ArrayList();
1526:
1527: while (rs.next()) {
1528: PatchBean patchInfo = new PatchBean();
1529: patchInfo.setFromTicket(rs.getInt("fromTicket_"));
1530: patchInfo.setToTicket(rs.getInt("toTicket_"));
1531: patchInfo.setComment(rs.getString("comment_"));
1532: patchInfo.setCreationDate(rs.getTimestamp("time_"));
1533: patchInfo.setWsName(rs.getString("wsName_"));
1534: patchInfo.setPatchSize(rs.getLong("xmlPatchSize_"));
1535: patchInfo.setTagName(rs.getString("tagName_"));
1536: patchInfo.setFiles(rs.getString("changeLog_"));
1537: patchInfo.setTagged(rs.getBoolean("tagged_"));
1538:
1539: //
1540: tmp.add(patchInfo);
1541: }
1542:
1543: // build result set
1544: PatchBean[] result = new PatchBean[tmp.size()];
1545:
1546: for (int i = 0; i < result.length; i++) {
1547: result[i] = (PatchBean) tmp.get(i);
1548: }
1549:
1550: return result;
1551: } catch (LibresourceSecurityException se) {
1552: throw se;
1553: } catch (URINotExistException se) {
1554: throw se;
1555: } catch (Exception e) {
1556: throw new LibresourceSynchronizerException(
1557: "Error in listSynchronizerPatch : "
1558: + e.getMessage(), e);
1559: } finally {
1560: // Close all db resource
1561: if (stmt != null) {
1562: try {
1563: stmt.close();
1564: } catch (SQLException e) {
1565: }
1566: }
1567:
1568: if (rs != null) {
1569: try {
1570: rs.close();
1571: } catch (SQLException e) {
1572: }
1573: }
1574:
1575: if (con != null) {
1576: try {
1577: con.close();
1578: } catch (SQLException e) {
1579: }
1580: }
1581: }
1582: }
1583:
1584: /**
1585: * @ejb.interface-method
1586: * @ejb.transaction type="Required"
1587: */
1588: public FileData getPatch(URI uri, long fromTicket)
1589: throws LibresourceSynchronizerException,
1590: LibresourceSecurityException, URINotExistException,
1591: InvalideTicketException {
1592: // SQL Object
1593: Connection con = null;
1594: Statement stmt = null;
1595: ResultSet rs = null;
1596:
1597: try {
1598: KernelService kernelService = (KernelService) Libresource
1599: .getService(KernelConstants.SERVICE);
1600:
1601: if (!(kernelService.checkSecurity(uri,
1602: KernelConstants.SECURITY_READ))) {
1603: throw new LibresourceSecurityException(uri,
1604: KernelConstants.SECURITY_READ);
1605: }
1606:
1607: //
1608: SynchronizerResourceValue synchronizerValue = getSynchronizer(uri);
1609: String synchronizerId = synchronizerValue.getId();
1610:
1611: // Find pacthName
1612: con = getConnection();
1613: stmt = con.createStatement();
1614:
1615: String query = "SELECT fromTicket_ , toTicket_ FROM ls_patch_"
1616: + synchronizerId
1617: + " WHERE fromTicket_ = "
1618: + fromTicket + " ORDER BY toTicket_ DESC";
1619: rs = stmt.executeQuery(query);
1620:
1621: if (rs.next()) {
1622: long toTicket = rs.getLong("toTicket_");
1623:
1624: String patchName = rs.getString("fromTicket_") + "."
1625: + rs.getString("toTicket_");
1626: String patchFileName = getSynchronizerBasePath(synchronizerId)
1627: + File.separator
1628: + "patchRepository"
1629: + File.separator + patchName;
1630:
1631: // Check if we need to extract it from DB
1632: File f = new File(patchFileName);
1633:
1634: if (!f.getParentFile().exists()) {
1635: f.getParentFile().mkdirs();
1636: }
1637:
1638: if (!f.exists()) {
1639: // Extract from db
1640: exportFileFromDatabase(fromTicket, toTicket,
1641: synchronizerId, con, patchFileName,
1642: "xmlPatch_");
1643: }
1644:
1645: // event
1646: LibresourceEvent event = new LibresourceEvent(
1647: uri,
1648: kernelService.lookup(uri),
1649: kernelService.getConnectedResource(),
1650: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_GET_PATCH);
1651: Libresource.throwEvent(event);
1652:
1653: return new FileDataImpl(f);
1654: } else {
1655: throw new InvalideTicketException(
1656: "No result found in bd ");
1657: }
1658: } catch (LibresourceSecurityException se) {
1659: throw se;
1660: } catch (URINotExistException se) {
1661: throw se;
1662: } catch (Exception e) {
1663: throw new LibresourceSynchronizerException(
1664: "Error in getPatch : " + e.getMessage(), e);
1665: } finally {
1666: // Close all db resource
1667: if (stmt != null) {
1668: try {
1669: stmt.close();
1670: } catch (SQLException e) {
1671: }
1672: }
1673:
1674: if (rs != null) {
1675: try {
1676: rs.close();
1677: } catch (SQLException e) {
1678: }
1679: }
1680:
1681: if (con != null) {
1682: try {
1683: con.close();
1684: } catch (SQLException e) {
1685: }
1686: }
1687: }
1688: }
1689:
1690: /**
1691: * @ejb.interface-method
1692: * @ejb.transaction type="Required"
1693: */
1694: public FileData getPatch(URI uri, long fromTicket, long toTicket)
1695: throws LibresourceSynchronizerException,
1696: LibresourceSecurityException, URINotExistException,
1697: InvalideTicketException {
1698: // SQL Object
1699: Connection con = null;
1700: Statement stmt = null;
1701: ResultSet rs = null;
1702:
1703: try {
1704: KernelService kernelService = (KernelService) Libresource
1705: .getService(KernelConstants.SERVICE);
1706:
1707: if (!(kernelService.checkSecurity(uri,
1708: KernelConstants.SECURITY_READ))) {
1709: throw new LibresourceSecurityException(uri,
1710: KernelConstants.SECURITY_READ);
1711: }
1712:
1713: //
1714: SynchronizerResourceValue synchronizerValue = getSynchronizer(uri);
1715: String synchronizerId = synchronizerValue.getId();
1716:
1717: // Find pacthName
1718: con = getConnection();
1719: stmt = con.createStatement();
1720:
1721: String query = "SELECT fromTicket_ , toTicket_ FROM ls_patch_"
1722: + synchronizerId
1723: + " WHERE fromTicket_ = "
1724: + fromTicket + " AND toTicket_ = " + toTicket;
1725: rs = stmt.executeQuery(query);
1726:
1727: if (rs.next()) {
1728: String patchName = rs.getString("fromTicket_") + "."
1729: + rs.getString("toTicket_");
1730: String patchFileName = getSynchronizerBasePath(synchronizerId)
1731: + File.separator
1732: + "patchRepository"
1733: + File.separator + patchName;
1734:
1735: // Check if we need to extract it from DB
1736: File f = new File(patchFileName);
1737:
1738: if (!f.getParentFile().exists()) {
1739: f.getParentFile().mkdirs();
1740: }
1741:
1742: if (!f.exists()) {
1743: // Extract from db
1744: exportFileFromDatabase(fromTicket, toTicket,
1745: synchronizerId, con, patchFileName,
1746: "xmlPatch_");
1747: }
1748:
1749: // event
1750: LibresourceEvent event = new LibresourceEvent(
1751: uri,
1752: kernelService.lookup(uri),
1753: kernelService.getConnectedResource(),
1754: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_GET_PATCH);
1755: Libresource.throwEvent(event);
1756:
1757: return new FileDataImpl(f);
1758: } else {
1759: throw new InvalideTicketException(
1760: "No result found in bd for patch " + fromTicket
1761: + " -> " + toTicket);
1762: }
1763: } catch (LibresourceSecurityException se) {
1764: throw se;
1765: } catch (URINotExistException se) {
1766: throw se;
1767: } catch (Exception e) {
1768: throw new LibresourceSynchronizerException(
1769: "Error in getPatch : " + e.getMessage(), e);
1770: } finally {
1771: // Close all db resource
1772: if (stmt != null) {
1773: try {
1774: stmt.close();
1775: } catch (SQLException e) {
1776: }
1777: }
1778:
1779: if (rs != null) {
1780: try {
1781: rs.close();
1782: } catch (SQLException e) {
1783: }
1784: }
1785:
1786: if (con != null) {
1787: try {
1788: con.close();
1789: } catch (SQLException e) {
1790: }
1791: }
1792: }
1793: }
1794:
1795: /**
1796: * @ejb.interface-method
1797: * @ejb.transaction type="Required"
1798: */
1799: public SynchronizerResourceValue[] listAllSynchronizers()
1800: throws LibresourceSynchronizerException {
1801: try {
1802: KernelService kernelService = (KernelService) Libresource
1803: .getService(KernelConstants.SERVICE);
1804: Collection syncs = SynchronizerResourceUtil.getLocalHome()
1805: .findAll();
1806: Vector allSyncs = new Vector();
1807:
1808: for (Iterator i = syncs.iterator(); i.hasNext();) {
1809: SynchronizerResourceLocal syncResourceLocal = (SynchronizerResourceLocal) i
1810: .next();
1811: LibresourceResourceIdentifier identifier = syncResourceLocal
1812: .getLibresourceResourceIdentifier();
1813:
1814: try {
1815: URI syncURI = kernelService.getMyURI(identifier);
1816: SynchronizerResourceValue resourceValue = syncResourceLocal
1817: .getSynchronizerResourceValue();
1818: resourceValue.setUri(syncURI);
1819: allSyncs.add(resourceValue);
1820: } catch (Exception e) {
1821: // lazy
1822: }
1823: }
1824:
1825: SynchronizerResourceValue[] result = new SynchronizerResourceValue[allSyncs
1826: .size()];
1827:
1828: for (int i = 0; i < result.length; i++) {
1829: result[i] = (SynchronizerResourceValue) allSyncs.get(i);
1830: }
1831:
1832: return result;
1833: } catch (Exception e) {
1834: throw new LibresourceSynchronizerException(
1835: "Can't list all synchronizers", e);
1836: }
1837: }
1838:
1839: /**
1840: * @ejb.interface-method
1841: * @ejb.transaction type="Required"
1842: */
1843: public void tagState(URI uri)
1844: throws LibresourceSynchronizerException,
1845: LibresourceSecurityException, URINotExistException {
1846: try {
1847: KernelService kernelService = (KernelService) Libresource
1848: .getService(KernelConstants.SERVICE);
1849:
1850: if (!kernelService.checkSecurity(uri, SO6_COMMIT)) {
1851: throw new LibresourceSecurityException(uri, SO6_COMMIT);
1852: }
1853:
1854: tagStateSystem(uri);
1855:
1856: // update node
1857: kernelService.setUpdateDate(uri, new Date());
1858: } catch (LibresourceSecurityException se) {
1859: throw se;
1860: } catch (URINotExistException se) {
1861: throw se;
1862: } catch (LibresourceSynchronizerException se) {
1863: throw se;
1864: } catch (Exception e) {
1865: throw new LibresourceSynchronizerException(
1866: "Error in tagState : " + e.getMessage(), e);
1867: } finally {
1868: }
1869: }
1870:
1871: /**
1872: * @ejb.interface-method
1873: * @ejb.transaction type="Required"
1874: */
1875: public void tagStateSystem(URI uri)
1876: throws LibresourceSynchronizerException,
1877: LibresourceSecurityException, URINotExistException {
1878: try {
1879: SynchronizerResourceValue synchronizerValue = getSynchronizer(uri);
1880:
1881: // String synchronizerId = synchronizerValue.getId();
1882: compressSynchronizerSystem(uri, 1, synchronizerValue
1883: .getLastTicket());
1884: } catch (LibresourceSecurityException se) {
1885: throw se;
1886: } catch (URINotExistException se) {
1887: throw se;
1888: } catch (Exception e) {
1889: throw new LibresourceSynchronizerException(
1890: "Error in tagState : " + e.getMessage(), e);
1891: }
1892: }
1893:
1894: /**
1895: * @ejb.interface-method
1896: * @ejb.transaction type="Required"
1897: */
1898: public void compressSynchronizer(URI uri, long from, long to)
1899: throws LibresourceSynchronizerException,
1900: LibresourceSecurityException, URINotExistException {
1901: try {
1902: KernelService kernelService = (KernelService) Libresource
1903: .getService(KernelConstants.SERVICE);
1904:
1905: if (!kernelService.checkSecurity(uri, SO6_COMMIT)) {
1906: throw new LibresourceSecurityException(uri, SO6_COMMIT);
1907: }
1908:
1909: compressSynchronizerSystem(uri, from, to);
1910:
1911: // update node
1912: kernelService.setUpdateDate(uri, new Date());
1913: } catch (LibresourceSecurityException se) {
1914: throw se;
1915: } catch (URINotExistException se) {
1916: throw se;
1917: } catch (LibresourceSynchronizerException se) {
1918: throw se;
1919: } catch (Exception e) {
1920: throw new LibresourceSynchronizerException(
1921: "Error in compressSynchronizer : " + e.getMessage(),
1922: e);
1923: } finally {
1924: }
1925: }
1926:
1927: /**
1928: * @ejb.interface-method
1929: * @ejb.transaction type="Required"
1930: */
1931: public void compressSynchronizerSystem(URI uri, long from, long to)
1932: throws LibresourceSynchronizerException,
1933: LibresourceSecurityException, URINotExistException {
1934: try {
1935: SynchronizerResourceValue synchronizerValue = getSynchronizer(uri);
1936: String synchronizerId = synchronizerValue.getId();
1937:
1938: try {
1939: getPatch(uri, from, to);
1940:
1941: return;
1942: } catch (LibresourceSynchronizerException e) {
1943: // patch does not exist yet...
1944: File patchRepository = new File(
1945: getSynchronizerBasePath(synchronizerId)
1946: + File.separator + "patchRepository");
1947: patchRepository.mkdirs();
1948:
1949: File outputFile = new File(patchRepository, from + "."
1950: + to);
1951:
1952: // find the shortest path
1953: PatchBean[] patchList = listSynchronizerPatch(uri, -1);
1954: long ticket = from;
1955: long tmp = -1;
1956: ArrayList path = new ArrayList();
1957:
1958: while (ticket <= to) {
1959: tmp = ticket;
1960:
1961: for (int i = 0; i < patchList.length; i++) {
1962: if (patchList[i].getFromTicket() == ticket) {
1963: if (tmp < patchList[i].getToTicket()) {
1964: tmp = patchList[i].getToTicket();
1965: }
1966: }
1967: }
1968:
1969: if (tmp <= to) {
1970: path.add(getPatch(uri, ticket, tmp));
1971: }
1972:
1973: ticket = tmp + 1;
1974: }
1975:
1976: File cmds = new File(
1977: getSynchronizerBasePath(synchronizerId)
1978: + File.separator + "CMDS");
1979: cmds.mkdirs();
1980:
1981: File attach = new File(
1982: getSynchronizerBasePath(synchronizerId)
1983: + File.separator + "ATTACH");
1984: attach.mkdirs();
1985:
1986: OpVectorFsImpl opv = new OpVectorFsImpl(cmds.getPath());
1987:
1988: // System.out.println("Patch list " + from + " " + to);
1989: for (Iterator i = path.iterator(); i.hasNext();) {
1990: FileData patchFile = (FileData) i.next();
1991: PatchFile pf = new PatchFile(patchFile.getName());
1992: pf.buildOpVector(patchFile.getInputStream(), opv,
1993: attach.getPath(), null);
1994: }
1995:
1996: // System.out.println("\nCompression start\n");
1997: CompressUtil.compressLog(opv);
1998:
1999: OutputStreamWriter osw = new FileWriter(outputFile);
2000: PatchFile.makePatch(opv, osw, null, from, to,
2001: "compress", "patch");
2002: osw.close();
2003: addPatchSystem(uri, from, to, new FileDataImpl(
2004: outputFile), "server made",
2005: "compressed by the server", System
2006: .currentTimeMillis(), false, true, "");
2007: }
2008: } catch (LibresourceSecurityException se) {
2009: throw se;
2010: } catch (URINotExistException se) {
2011: throw se;
2012: } catch (Exception e) {
2013: throw new LibresourceSynchronizerException(
2014: "Error in compressSynchronizer : " + e.getMessage(),
2015: e);
2016: }
2017: }
2018:
2019: /**
2020: * @ejb.interface-method
2021: * @ejb.transaction type="Required"
2022: */
2023: public int importFileInDbSystem(FileData patchfile)
2024: throws Exception {
2025: Connection con = null;
2026: Statement stmt = null;
2027: ResultSet rs = null;
2028:
2029: try {
2030: con = getConnection();
2031: stmt = con.createStatement();
2032:
2033: // write tmp file
2034: File dir = new File(getDistributedFileSystem()
2035: + File.separator + "syncTmp");
2036: dir.mkdirs();
2037:
2038: File tmpFile = File.createTempFile("ejbImport", null, dir);
2039:
2040: BufferedOutputStream bos = new BufferedOutputStream(
2041: new FileOutputStream(tmpFile));
2042: BufferedInputStream bis = new BufferedInputStream(patchfile
2043: .getInputStream());
2044: byte[] buffer = new byte[BUFFER_SIZE];
2045: int length;
2046:
2047: while ((length = bis.read(buffer)) != -1) {
2048: bos.write(buffer, 0, length);
2049: }
2050:
2051: bos.flush();
2052: bos.close();
2053: bis.close();
2054:
2055: // import file in db
2056: String query = "SELECT lo_import('"
2057: + tmpFile.getPath().replaceAll("\\\\", "/") + "')";
2058: rs = stmt.executeQuery(query);
2059:
2060: if (rs.next()) {
2061: return rs.getInt(1);
2062: }
2063:
2064: throw new Exception("Error in importing file in db");
2065: } finally {
2066: if (stmt != null) {
2067: try {
2068: stmt.close();
2069: } catch (SQLException e) {
2070: }
2071: }
2072:
2073: if (rs != null) {
2074: try {
2075: rs.close();
2076: } catch (SQLException e) {
2077: }
2078: }
2079:
2080: if (con != null) {
2081: try {
2082: con.close();
2083: } catch (SQLException e) {
2084: }
2085: }
2086: }
2087: }
2088:
2089: /**
2090: * @ejb.interface-method
2091: * @ejb.transaction type="Required"
2092: */
2093: public void insertPatchMetaDataSystem(URI uri, String syncId,
2094: long fromTicket, long toTicket, String wsName,
2095: String comment, int patchOID, long patchSize, long time,
2096: boolean builtPatch, String changeLog) throws Exception {
2097: Connection con = null;
2098: PreparedStatement pstmt = null;
2099: String query = "INSERT INTO ls_patch_"
2100: + syncId
2101: + " (fromTicket_ ,toTicket_ , wsName_ , comment_ , time_ ,xmlPatch_, xmlPatchSize_,builtPatch,tagged_,changeLog_) VALUES (?,?,?,?,?,?,?,?,?,?)";
2102:
2103: try {
2104: con = getConnection();
2105: pstmt = con.prepareStatement(query);
2106: pstmt.setLong(1, fromTicket);
2107: pstmt.setLong(2, toTicket);
2108: pstmt.setString(3, wsName);
2109: pstmt.setString(4, comment);
2110: pstmt.setTimestamp(5, new Timestamp(time));
2111: pstmt.setInt(6, patchOID);
2112: pstmt.setLong(7, patchSize);
2113: pstmt.setBoolean(8, builtPatch);
2114: pstmt.setBoolean(9, false);
2115: pstmt.setString(10, changeLog);
2116: pstmt.executeUpdate();
2117:
2118: // update synchronizer
2119: KernelService kernelService = (KernelService) Libresource
2120: .getService(KernelConstants.SERVICE);
2121: LibresourceResourceIdentifier resourceIdentifier = kernelService
2122: .lookup(uri);
2123: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2124: .findResource(resourceIdentifier,
2125: SynchronizerResourceLocal.class);
2126:
2127: if (synchronizerResourceLocal.getLastTicket() < toTicket) {
2128: synchronizerResourceLocal.setLastTicket(toTicket);
2129: }
2130:
2131: // event
2132: if (!"compressed by the server".equals(comment)) {
2133: LibresourceEvent event = new LibresourceEvent(
2134: uri,
2135: resourceIdentifier,
2136: kernelService.getConnectedResource(),
2137: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_ADD_PATCH,
2138: comment);
2139: Libresource.throwEvent(event);
2140: }
2141: } finally {
2142: // Close loca db resource
2143: if (pstmt != null) {
2144: try {
2145: pstmt.close();
2146: } catch (SQLException e) {
2147: }
2148: }
2149:
2150: if (con != null) {
2151: try {
2152: con.close();
2153: } catch (SQLException e) {
2154: }
2155: }
2156: }
2157: }
2158:
2159: /**
2160: * @ejb.interface-method
2161: * @ejb.transaction type="Required"
2162: */
2163: public void editPatch(URI uri, long fromTicket, long toTicket,
2164: String comment, String tagName, boolean tagged)
2165: throws Exception {
2166: Connection con = null;
2167: PreparedStatement pstmt = null;
2168:
2169: try {
2170: KernelService kernelService = (KernelService) Libresource
2171: .getService(KernelConstants.SERVICE);
2172:
2173: if (!kernelService.checkSecurity(uri,
2174: KernelConstants.SECURITY_UPDATE)) {
2175: throw new LibresourceSecurityException(uri,
2176: KernelConstants.SECURITY_UPDATE);
2177: }
2178:
2179: // get synchronizer
2180: LibresourceResourceIdentifier resourceIdentifier = kernelService
2181: .lookup(uri);
2182: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2183: .findResource(resourceIdentifier,
2184: SynchronizerResourceLocal.class);
2185: String query = "UPDATE ls_patch_"
2186: + synchronizerResourceLocal.getId()
2187: + " SET comment_ = ? , tagged_ = ? , tagName_ = ? WHERE fromTicket_ = ? AND toTicket_ = ?";
2188:
2189: //
2190: con = getConnection();
2191: pstmt = con.prepareStatement(query);
2192: pstmt.setString(1, comment);
2193: pstmt.setBoolean(2, tagged);
2194: pstmt.setString(3, tagName);
2195: pstmt.setLong(4, fromTicket);
2196: pstmt.setLong(5, toTicket);
2197: pstmt.executeUpdate();
2198:
2199: // update node
2200: kernelService.setUpdateDate(uri, new Date());
2201:
2202: // event
2203: LibresourceEvent event = new LibresourceEvent(
2204: uri,
2205: resourceIdentifier,
2206: kernelService.getConnectedResource(),
2207: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_EDIT_PATCH,
2208: comment);
2209: Libresource.throwEvent(event);
2210: } finally {
2211: // Close loca db resource
2212: if (pstmt != null) {
2213: try {
2214: pstmt.close();
2215: } catch (SQLException e) {
2216: }
2217: }
2218:
2219: if (con != null) {
2220: try {
2221: con.close();
2222: } catch (SQLException e) {
2223: }
2224: }
2225: }
2226: }
2227:
2228: /**
2229: * @ejb.interface-method
2230: * @ejb.transaction type="Required"
2231: */
2232: public void addPatch(URI uri, long fromTicket, long toTicket,
2233: FileData patchfile, String wsName, String comment,
2234: long time, boolean validateTicketNumber, String changeLog)
2235: throws LibresourceSynchronizerException,
2236: InvalideTicketException, LibresourceSecurityException,
2237: URINotExistException {
2238: try {
2239: KernelService kernelService = (KernelService) Libresource
2240: .getService(KernelConstants.SERVICE);
2241:
2242: if (!(kernelService.checkSecurity(uri, SO6_COMMIT))) {
2243: throw new LibresourceSecurityException(uri, SO6_COMMIT);
2244: }
2245:
2246: addPatchSystem(uri, fromTicket, toTicket, patchfile,
2247: wsName, comment, time, validateTicketNumber,
2248: !validateTicketNumber, changeLog);
2249:
2250: // update node
2251: kernelService.setUpdateDate(uri, new Date());
2252: } catch (InvalideTicketException se) {
2253: throw se;
2254: } catch (LibresourceSecurityException se) {
2255: throw se;
2256: } catch (URINotExistException se) {
2257: throw se;
2258: } catch (LibresourceSynchronizerException se) {
2259: throw se;
2260: } catch (Exception e) {
2261: throw new LibresourceSynchronizerException(
2262: "Error in addPatch : " + e.getMessage(), e);
2263: } finally {
2264: }
2265: }
2266:
2267: /**
2268: * @ejb.interface-method
2269: * @ejb.transaction type="Required"
2270: */
2271: public void addPatchSystem(URI uri, long fromTicket, long toTicket,
2272: FileData patchfile, String wsName, String comment,
2273: long time, boolean validateTicketNumber,
2274: boolean builtPatch, String changeLog)
2275: throws LibresourceSynchronizerException,
2276: LibresourceSecurityException, URINotExistException,
2277: InvalideTicketException {
2278: long start = System.currentTimeMillis();
2279:
2280: try {
2281: KernelService kernelService = (KernelService) Libresource
2282: .getService(KernelConstants.SERVICE);
2283:
2284: /*
2285: * if (!(kernelService.checkSecurity(uri, SO6_COMMIT))) throw new
2286: * LibresourceSecurityException(uri, SO6_COMMIT);
2287: */
2288:
2289: // get synchronizer
2290: LibresourceResourceIdentifier resourceIdentifier = kernelService
2291: .lookup(uri);
2292: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2293: .findResource(resourceIdentifier,
2294: SynchronizerResourceLocal.class);
2295:
2296: if (validateTicketNumber
2297: && (fromTicket != (synchronizerResourceLocal
2298: .getLastTicket() + 1))) {
2299: throw new InvalideTicketException(
2300: "Invalide ticket number ( expected "
2301: + (synchronizerResourceLocal
2302: .getLastTicket() + 1) + " got "
2303: + fromTicket);
2304: }
2305:
2306: String synchronizerId = synchronizerResourceLocal.getId();
2307:
2308: // Synchronizer service
2309: LibresourceSynchronizerService synchronizerService = (LibresourceSynchronizerService) Libresource
2310: .getService(LibresourceSynchronizerConstants.SERVICE);
2311:
2312: // insert file in db
2313: int oid = synchronizerService
2314: .importFileInDbSystem(patchfile);
2315:
2316: // insert patch meta information
2317: synchronizerService.insertPatchMetaDataSystem(uri,
2318: synchronizerId, fromTicket, toTicket, wsName,
2319: comment, oid, patchfile.getSize(), time,
2320: builtPatch, changeLog);
2321: } catch (LibresourceSecurityException se) {
2322: throw se;
2323: } catch (URINotExistException se) {
2324: throw se;
2325: } catch (Exception e) {
2326: throw new LibresourceSynchronizerException(
2327: "Error in addPatchSystem : " + e.getMessage(), e);
2328: } finally {
2329: }
2330: }
2331:
2332: /**
2333: * @ejb.interface-method
2334: * @ejb.transaction type="Required"
2335: */
2336: public void removePatch(URI uri, long fromTicket, long toTicket)
2337: throws LibresourceSynchronizerException,
2338: LibresourceSecurityException, URINotExistException {
2339: Connection con = null;
2340: PreparedStatement pstmt = null;
2341: String query = "DELETE FROM ls_patch_"
2342: + getSynchronizer(uri).getId()
2343: + " WHERE fromTicket_ = ? AND toTicket = ?";
2344:
2345: try {
2346: con = getConnection();
2347: pstmt = con.prepareStatement(query);
2348: pstmt.setLong(1, fromTicket);
2349: pstmt.setLong(2, toTicket);
2350: pstmt.executeUpdate();
2351:
2352: // update synchronizer
2353: KernelService kernelService = (KernelService) Libresource
2354: .getService(KernelConstants.SERVICE);
2355:
2356: if (!(kernelService.checkSecurity(uri, SO6_COMMIT))) {
2357: throw new LibresourceSecurityException(uri, SO6_COMMIT);
2358: }
2359:
2360: // get synchronizer
2361: LibresourceResourceIdentifier resourceIdentifier = kernelService
2362: .lookup(uri);
2363: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2364: .findResource(resourceIdentifier,
2365: SynchronizerResourceLocal.class);
2366:
2367: if (synchronizerResourceLocal.getLastTicket() < toTicket) {
2368: synchronizerResourceLocal.setLastTicket(toTicket);
2369: }
2370:
2371: // update node
2372: kernelService.setUpdateDate(uri, new Date());
2373:
2374: // event
2375: LibresourceEvent event = new LibresourceEvent(
2376: uri,
2377: resourceIdentifier,
2378: kernelService.getConnectedResource(),
2379: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_REMOVE_PATCH,
2380: fromTicket + "-" + toTicket);
2381: Libresource.throwEvent(event);
2382: } catch (LibresourceSecurityException se) {
2383: throw se;
2384: } catch (URINotExistException se) {
2385: throw se;
2386: } catch (Exception e) {
2387: throw new LibresourceSynchronizerException(
2388: "Error in removePatch : " + e.getMessage(), e);
2389: } finally {
2390: // Close loca db resource
2391: if (pstmt != null) {
2392: try {
2393: pstmt.close();
2394: } catch (SQLException e) {
2395: }
2396: }
2397:
2398: if (con != null) {
2399: try {
2400: con.close();
2401: } catch (SQLException e) {
2402: }
2403: }
2404: }
2405: }
2406:
2407: /**
2408: * @ejb.interface-method
2409: * @ejb.transaction type="Required"
2410: */
2411: public String getBinExt(URI uri)
2412: throws LibresourceSynchronizerException,
2413: LibresourceSecurityException, URINotExistException {
2414: return getSynchronizer(uri).getBinaryExtention();
2415: }
2416:
2417: /**
2418: * @ejb.interface-method
2419: * @ejb.transaction type="Required"
2420: */
2421: public void addBinExt(URI uri, String ext)
2422: throws LibresourceSynchronizerException,
2423: LibresourceSecurityException, URINotExistException {
2424: try {
2425: KernelService kernelService = (KernelService) Libresource
2426: .getService(KernelConstants.SERVICE);
2427:
2428: if (!kernelService.checkSecurity(uri,
2429: KernelConstants.SECURITY_UPDATE)) {
2430: throw new LibresourceSecurityException(uri,
2431: KernelConstants.SECURITY_UPDATE);
2432: }
2433:
2434: // Synchronier
2435: LibresourceResourceIdentifier resourceIdentifier = kernelService
2436: .lookup(uri);
2437: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2438: .findResource(resourceIdentifier,
2439: SynchronizerResourceLocal.class);
2440:
2441: // old binary extention
2442: String oldBinExt = synchronizerResourceLocal
2443: .getBinaryExtention();
2444:
2445: // update if needed
2446: if (oldBinExt.indexOf(ext) == -1) {
2447: synchronizerResourceLocal.setBinaryExtention(oldBinExt
2448: + " " + ext);
2449: }
2450:
2451: // update node
2452: kernelService.setUpdateDate(uri, new Date());
2453: } catch (LibresourceSecurityException se) {
2454: ctx.setRollbackOnly();
2455: throw se;
2456: } catch (URINotExistException se) {
2457: ctx.setRollbackOnly();
2458: throw se;
2459: } catch (Exception e) {
2460: ctx.setRollbackOnly();
2461: throw new LibresourceSynchronizerException(
2462: "Error in addBinExt : " + e.getMessage(), e);
2463: }
2464: }
2465:
2466: /**
2467: * @ejb.interface-method
2468: * @ejb.transaction type="Required"
2469: */
2470: public void removeBinExt(URI uri, String ext)
2471: throws LibresourceSynchronizerException,
2472: LibresourceSecurityException, URINotExistException {
2473: try {
2474: KernelService kernelService = (KernelService) Libresource
2475: .getService(KernelConstants.SERVICE);
2476:
2477: if (!kernelService.checkSecurity(uri,
2478: KernelConstants.SECURITY_UPDATE)) {
2479: throw new LibresourceSecurityException(uri,
2480: KernelConstants.SECURITY_UPDATE);
2481: }
2482:
2483: // Synchronier
2484: LibresourceResourceIdentifier resourceIdentifier = kernelService
2485: .lookup(uri);
2486: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2487: .findResource(resourceIdentifier,
2488: SynchronizerResourceLocal.class);
2489:
2490: // old binary extention
2491: StringBuffer binExt = new StringBuffer();
2492: binExt.append(synchronizerResourceLocal
2493: .getBinaryExtention());
2494:
2495: // update if needed
2496: if (binExt.indexOf(ext) != -1) {
2497: int pos = binExt.indexOf(ext);
2498: binExt.replace(pos, ext.length() + pos, "");
2499: synchronizerResourceLocal.setBinaryExtention(binExt
2500: .toString());
2501: }
2502:
2503: // update node
2504: kernelService.setUpdateDate(uri, new Date());
2505: } catch (LibresourceSecurityException se) {
2506: ctx.setRollbackOnly();
2507: throw se;
2508: } catch (URINotExistException se) {
2509: ctx.setRollbackOnly();
2510: throw se;
2511: } catch (Exception e) {
2512: ctx.setRollbackOnly();
2513: throw new LibresourceSynchronizerException(
2514: "Error in removeBinExt : " + e.getMessage(), e);
2515: }
2516: }
2517:
2518: // Database connectivity
2519: public static Connection getConnection() throws SQLException,
2520: NamingException {
2521: return Libresource.getDatasource().getConnection();
2522: }
2523:
2524: public void importFileIntoDatabase(String ticketField, long ticket,
2525: String synchronizerId, Connection con, String filePath,
2526: String fieldName) throws SQLException {
2527: String validatePath = filePath.replaceAll("\\\\", "/");
2528: PreparedStatement addFile = con
2529: .prepareStatement("UPDATE ls_patch_" + synchronizerId
2530: + " SET " + fieldName + " = lo_import('"
2531: + validatePath + "') WHERE " + ticketField
2532: + " =?");
2533: addFile.setLong(1, ticket);
2534: addFile.executeUpdate();
2535: addFile.close();
2536: }
2537:
2538: public void exportFileFromDatabase(long fromTicket, long toTicket,
2539: String synchronizerId, Connection con, String filePath,
2540: String fieldName) throws LibresourceSynchronizerException {
2541: // export file on root of disributedFileSystem
2542: LibresourceCoreService coreService;
2543: File tmpFile;
2544:
2545: try {
2546: coreService = (LibresourceCoreService) Libresource
2547: .getService("LibresourceCore");
2548: tmpFile = coreService.createTempFile(synchronizerId
2549: + "_patch_" + fromTicket + "_" + toTicket);
2550:
2551: PreparedStatement exportFile = con
2552: .prepareStatement("SELECT lo_export(" + fieldName
2553: + ",?) FROM ls_patch_" + synchronizerId
2554: + " WHERE fromTicket_ =? AND toTicket_ = ?");
2555: exportFile.setString(1, tmpFile.getAbsolutePath());
2556: exportFile.setLong(2, fromTicket);
2557: exportFile.setLong(3, toTicket);
2558: exportFile.executeQuery();
2559: exportFile.close();
2560:
2561: FileUtils.copy(tmpFile.getAbsolutePath(), filePath);
2562: } catch (Exception e) {
2563: throw new LibresourceSynchronizerException(e.getMessage());
2564: }
2565: }
2566:
2567: public static String getCreatePatchTableQuery(String synchronizerId)
2568: throws SQLException {
2569: StringBuffer buffer = new StringBuffer();
2570: buffer.append("CREATE TABLE ls_patch_");
2571: buffer.append(synchronizerId);
2572: buffer.append(PATCH_TABLE_PARAM);
2573:
2574: return buffer.toString();
2575: }
2576:
2577: public static String getSynchronizerBasePath(String synchronizerId)
2578: throws LibresourceSynchronizerException {
2579: return getDistributedFileSystem() + File.separator
2580: + "synchronizerData" + File.separator + synchronizerId;
2581: }
2582:
2583: public static String getDistributedFileSystem()
2584: throws LibresourceSynchronizerException {
2585: try {
2586: LibresourceCoreService coreService = (LibresourceCoreService) LibresourceCoreServiceUtil
2587: .getHome().create();
2588:
2589: return coreService.getDistributedFileSystem();
2590: } catch (Exception e) {
2591: throw new LibresourceSynchronizerException(
2592: "Error in getDistributedFileSystem : "
2593: + e.getMessage(), e);
2594: }
2595: }
2596:
2597: // libresource service
2598:
2599: /**
2600: * @ejb.interface-method
2601: * @ejb.transaction type="Required"
2602: */
2603: public LibresourceExportHandler getXmlExportHandlerForResource(
2604: URI uri) throws LibresourceException {
2605: try {
2606: KernelService kernelService = (KernelService) Libresource
2607: .getService(KernelConstants.SERVICE);
2608: LibresourceResourceIdentifier resourceIdentifier = kernelService
2609: .lookup(uri);
2610:
2611: try {
2612: Libresource.checkType(resourceIdentifier,
2613: SynchronizerResourceLocal.class);
2614:
2615: SynchronizerExportHandler exportHandler = new SynchronizerExportHandler(
2616: uri);
2617:
2618: return exportHandler;
2619: } catch (Exception e) {
2620: //
2621: }
2622:
2623: try {
2624: Libresource.checkType(resourceIdentifier,
2625: WsConnectionResourceLocal.class);
2626:
2627: WsConnectionExportHandler exportHandler = new WsConnectionExportHandler(
2628: uri);
2629:
2630: return exportHandler;
2631: } catch (Exception e) {
2632: //
2633: }
2634:
2635: return super .getXmlExportHandlerForResource(uri);
2636: } catch (Exception e) {
2637: throw new LibresourceException(
2638: "Can't obtain exportHandler for uri " + uri, e);
2639: }
2640: }
2641:
2642: /**
2643: * @ejb.interface-method
2644: * @ejb.transaction type="Required"
2645: */
2646: public LibresourceImportHandler getXmlImportHandler(String type)
2647: throws LibresourceException {
2648: if (type
2649: .equals(LibresourceSynchronizerConstants.RESOURCE_SYNCHRONIZER)) {
2650: return new SynchronizerImportHandler();
2651: }
2652:
2653: if (type
2654: .equals(LibresourceSynchronizerConstants.RESOURCE_WS_CONNECTION)) {
2655: return new WsConnectionImportHandler();
2656: }
2657:
2658: return super .getXmlImportHandler(type);
2659: }
2660:
2661: /**
2662: * @ejb.interface-method
2663: * @ejb.transaction type="Required"
2664: */
2665: public String[] listAvailablesPermissions(
2666: LibresourceResourceIdentifier resourceIdentifier)
2667: throws LibresourceException {
2668: try {
2669: Libresource.checkType(resourceIdentifier,
2670: SynchronizerResourceLocal.class);
2671:
2672: String[] result = new String[2];
2673: result[0] = SO6_COMMIT;
2674: result[1] = SO6_CREATE_WORKSPACE;
2675:
2676: return result;
2677: } catch (LibresourceException e) {
2678: //
2679: }
2680:
2681: try {
2682: Libresource.checkType(resourceIdentifier,
2683: WsConnectionResourceLocal.class);
2684:
2685: return null;
2686: } catch (LibresourceException e) {
2687: //
2688: }
2689:
2690: return null;
2691: }
2692:
2693: /**
2694: * @ejb.interface-method
2695: * @ejb.transaction type="Required"
2696: */
2697: public String[] listAvailablesEvents(
2698: LibresourceResourceIdentifier resourceIdentifier)
2699: throws LibresourceException {
2700: if (resourceIdentifier.getService().equals(
2701: LibresourceSynchronizerConstants.SERVICE)) {
2702: if (resourceIdentifier
2703: .getResourceType()
2704: .equals(
2705: LibresourceSynchronizerConstants.RESOURCE_SYNCHRONIZER)) {
2706: return new String[] {
2707: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_CREATE,
2708: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_EDIT,
2709: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_GET_PATCH,
2710: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_ADD_PATCH,
2711: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_EDIT_PATCH,
2712: LibresourceSynchronizerConstants.EVENT_SYNCHRONIZER_REMOVE_PATCH };
2713: }
2714:
2715: if (resourceIdentifier
2716: .getResourceType()
2717: .equals(
2718: LibresourceSynchronizerConstants.RESOURCE_WS_CONNECTION)) {
2719: return new String[] {
2720: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_CREATE,
2721: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_EDIT,
2722: LibresourceSynchronizerConstants.EVENT_WORKSPACE_CONNECTION_UPDATELASTTICKET };
2723: }
2724: }
2725:
2726: return super .listAvailablesPermissions(resourceIdentifier);
2727: }
2728:
2729: /**
2730: * @ejb.interface-method
2731: * @ejb.transaction type="Required"
2732: */
2733: public LibresourceIndexableContent getIndexableContent(
2734: LibresourceResourceIdentifier resourceIdentifier)
2735: throws LibresourceException {
2736: try {
2737: try {
2738: Libresource.checkType(resourceIdentifier,
2739: SynchronizerResourceLocal.class);
2740:
2741: LibresourceIndexableContent content = new LibresourceIndexableContent();
2742: SynchronizerResourceLocal synchronizerResourceLocal = (SynchronizerResourceLocal) Libresource
2743: .findResource(resourceIdentifier);
2744: content.addContentPart(synchronizerResourceLocal
2745: .getName());
2746: content.addContentPart(synchronizerResourceLocal
2747: .getDescription());
2748:
2749: return content;
2750: } catch (LibresourceException e) {
2751: //
2752: }
2753:
2754: try {
2755: Libresource.checkType(resourceIdentifier,
2756: WsConnectionResourceLocal.class);
2757:
2758: LibresourceIndexableContent content = new LibresourceIndexableContent();
2759: WsConnectionResourceLocal resourceLocal = (WsConnectionResourceLocal) Libresource
2760: .findResource(resourceIdentifier);
2761: content.addContentPart(resourceLocal.getName());
2762:
2763: return content;
2764: } catch (LibresourceException e) {
2765: //
2766: }
2767:
2768: return null;
2769: } catch (Exception e) {
2770: throw new LibresourceException(
2771: "error in LibresourceSynchronizer.getIndexableContent("
2772: + resourceIdentifier + ")", e);
2773: }
2774: }
2775: }
|