Package org.exoplatform.services.jcr.impl.core

Examples of org.exoplatform.services.jcr.impl.core.SessionDataManager


    * Is a predecessor of the merge version
    */
   protected boolean isPredecessor(TransientNodeData mergeVersion, TransientNodeData corrVersion)
            throws RepositoryException
   {
      SessionDataManager mergeDataManager = mergeSession.getTransientNodesManager();

      PropertyData predecessorsProperty =
               (PropertyData) mergeDataManager.getItemData(mergeVersion, new QPathEntry(Constants.JCR_PREDECESSORS, 0));

      if (predecessorsProperty != null)
         for (ValueData pv : predecessorsProperty.getValues())
         {
            try
            {
               String pidentifier = new String(pv.getAsByteArray());

               if (pidentifier.equals(corrVersion.getIdentifier()))
                  return true; // got it

               // search in predecessors of the predecessor
               TransientNodeData predecessor = (TransientNodeData) mergeDataManager.getItemData(pidentifier);
               if (predecessor != null)
               {
                  if (isPredecessor(predecessor, corrVersion))
                  {
                     return true;
View Full Code Here


    * Is a successor of the merge version
    */
   protected boolean isSuccessor(TransientNodeData mergeVersion, TransientNodeData corrVersion)
            throws RepositoryException
   {
      SessionDataManager mergeDataManager = mergeSession.getTransientNodesManager();

      PropertyData successorsProperty =
               (PropertyData) mergeDataManager.getItemData(mergeVersion, new QPathEntry(Constants.JCR_SUCCESSORS, 0));

      if (successorsProperty != null)
         for (ValueData sv : successorsProperty.getValues())
         {
            try
            {
               String sidentifier = new String(sv.getAsByteArray());

               if (sidentifier.equals(corrVersion.getIdentifier()))
                  return true; // got it

               // search in successors of the successor
               TransientNodeData successor = (TransientNodeData) mergeDataManager.getItemData(sidentifier);
               if (successor != null)
               {
                  if (isSuccessor(successor, corrVersion))
                  {
                     return true;
View Full Code Here

         {
            // for each child node of n' in D' copy it (and its subtree) to n
            // as a new child node (if an incoming node has the same
            // UUID as a node already existing in this workspace,
            // the already existing node is removed).
            SessionDataManager mergeDataManager = mergeSession.getTransientNodesManager();
            for (NodeData corrNode : context.getCorrChildNodes())
            {
               NodeData existedSameIdentifier = (NodeData)mergeDataManager.getItemData(corrNode.getIdentifier());
               if (existedSameIdentifier != null)
               {
                  // if an incoming node has the same
                  // UUID as a node already existing in this workspace,
                  // the already existing node is removed
View Full Code Here

            if (corrVersion != null)
            {
               // let v be base version of n.
               // let v' be base version of n'.

               SessionDataManager mergeDataManager = mergeSession.getTransientNodesManager();

               PropertyData isCheckedOutProperty =
                  (PropertyData)mergeDataManager.getItemData(mergeNode, new QPathEntry(Constants.JCR_ISCHECKEDOUT, 0));

               try
               {
                  if (!Boolean.valueOf(new String(isCheckedOutProperty.getValues().get(0).getAsByteArray()))
                     && isSuccessor(mergeVersion, corrVersion))
View Full Code Here

      NodeTypeDataManager ntManager = session.getWorkspace().getNodeTypesHolder();
      if (ntManager.isNodeType(Constants.MIX_VERSIONABLE, node.getPrimaryTypeName(), node.getMixinTypeNames()))
      {

         SessionDataManager dmanager = session.getTransientNodesManager();

         PropertyData bvProperty =
            (PropertyData)dmanager.getItemData(node, new QPathEntry(Constants.JCR_BASEVERSION, 0));

         try
         {
            return (NodeData)dmanager.getItemData(new String(bvProperty.getValues().get(0).getAsByteArray()));
         }
         catch (IOException e)
         {
            throw new RepositoryException("Merge. Get base version error " + e.getMessage(), e);
         }
View Full Code Here

      checkIfAuditable(currentItem);

      AuditSession auditSession = new AuditSession(currentItem);
      SessionImpl session = (SessionImpl)currentItem.getSession();

      SessionDataManager dataManager = auditSession.getDataManager();

      NodeData auditHistory = auditSession.getAuditHistoryNodeData();
      if (auditHistory == null)
      {
         throw new PathNotFoundException("Audit history not found for " + currentItem.getPath());
      }

      // make path to the AUDITHISTORY_LASTRECORD property
      QPath path = QPath.makeChildPath(auditHistory.getQPath(), AuditService.EXO_AUDITHISTORY_LASTRECORD);
      // searching last name of node
      PropertyData pData = (PropertyData)dataManager.getItemData(path);
      String auditRecordName = String.valueOf(ValueDataUtil.getLong(pData.getValues().get(0)) + 1);

      // exo:auditRecord
      List<AccessControlEntry> access = new ArrayList<AccessControlEntry>();
      access.add(new AccessControlEntry(defaultIdentity, PermissionType.SET_PROPERTY));
      access.add(new AccessControlEntry(defaultIdentity, PermissionType.READ));

      for (String identity : adminIdentitys)
      {
         access.add(new AccessControlEntry(identity, PermissionType.REMOVE));
      }

      AccessControlList exoAuditRecordAccessControlList = new AccessControlList(session.getUserID(), access);

      TransientNodeData arNode =
         new TransientNodeData(QPath.makeChildPath(auditHistory.getQPath(), new InternalQName(null, auditRecordName)),
            IdGenerator.generate(), -1, AuditService.EXO_AUDITRECORD, new InternalQName[0],
            Integer.parseInt(auditRecordName), auditHistory.getIdentifier(), exoAuditRecordAccessControlList);

      // exo:auditRecord
      dataManager.update(new ItemState(arNode, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);

      // jcr:primaryType
      TransientPropertyData arPrType =
         TransientPropertyData.createPropertyData(arNode, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false,
            new TransientValueData(arNode.getPrimaryTypeName()));
      // exo:user
      TransientPropertyData arUser =
         TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_USER, PropertyType.STRING,
            false, new TransientValueData(session.getUserID()));
      // exo:created
      TransientPropertyData arCreated =
         TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_CREATED, PropertyType.DATE,
            false, new TransientValueData(dataManager.getTransactManager().getStorageDataManager().getCurrentTime()));
      // exo:eventType
      TransientPropertyData arEventType =
         TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_EVENTTYPE, PropertyType.LONG,
            false, new TransientValueData(eventType));

      // jcr:primaryType
      dataManager.update(new ItemState(arPrType, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()),
         true);

      // exo:user
      dataManager.update(new ItemState(arUser, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);

      // exo:created
      dataManager.update(new ItemState(arCreated, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()),
         true);

      // exo:eventType
      dataManager.update(new ItemState(arEventType, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()),
         true);

      if (!currentItem.isNode())
      {
         int propertyType = ((Property)currentItem).getType();

         if (propertyType != PropertyType.BINARY)
         {

            // exo:newValue
            TransientPropertyData arNewValue =
               TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_NEWVALUE, propertyType,
                  ((PropertyImpl)currentItem).isMultiValued(),
                  ((PropertyData)((PropertyImpl)currentItem).getData()).getValues());

            dataManager.update(
               new ItemState(arNewValue, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);

            if (eventType == Event.PROPERTY_CHANGED)
            {

               // exo:oldValue
               TransientPropertyData arOldValue =
                  TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_OLDVALUE, propertyType,
                     ((PropertyImpl)previousItem).isMultiValued(),
                     ((PropertyData)((PropertyImpl)previousItem).getData()).getValues());

               dataManager.update(
                  new ItemState(arOldValue, ItemState.ADDED, true, ((ItemImpl)previousItem).getInternalPath()), true);
            }
         }
      }

      NodeData vancestor; // nearest versionable ancestor
      if (currentItem.isNode())
      {
         vancestor = ((NodeImpl)currentItem).getVersionableAncestor();
      }
      else
      {
         vancestor = ((NodeImpl)((Property)currentItem).getParent()).getVersionableAncestor();

         // exo:propertyName
         TransientPropertyData propertyNameData =
            TransientPropertyData.createPropertyData(arNode, EXO_AUDITRECORD_PROPERTYNAME, PropertyType.STRING, false,
               new TransientValueData(((ItemImpl)currentItem).getInternalName()));
         dataManager.update(
            new ItemState(propertyNameData, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);
      }

      if (vancestor != null)
      {
         // auditable node under a version control, set related properties to the
         // audit record

         String versionUUID; // current base version UUID
         StringBuilder versionName = new StringBuilder(); // current base version name + labels

         PropertyData bvProp =
            (PropertyData)dataManager.getItemData(vancestor, new QPathEntry(Constants.JCR_BASEVERSION, 1),
               ItemType.PROPERTY);

         versionUUID = ValueDataUtil.getString(bvProp.getValues().get(0));

         // using JCR API objects
         Version version = (Version)dataManager.getItemByIdentifier(versionUUID, false);
         versionName = new StringBuilder(version.getName());

         if (!dataManager.isNew(version.getParent().getUUID()))
         {
            VersionHistory versionHistory =
               (VersionHistory)dataManager.getItemByIdentifier(version.getParent().getUUID(), false);
            String[] labels = versionHistory.getVersionLabels(version);
            for (int i = 0; i < labels.length; i++)
            {
               String vl = labels[i];
               if (i == 0)
               {
                  versionName.append(" ");
               }
               versionName.append("'").append(vl).append("' ");
            }
         }

         TransientPropertyData auditVersion =
            TransientPropertyData.createPropertyData(arNode, EXO_AUDITRECORD_AUDITVERSION, PropertyType.STRING, false,
               new TransientValueData(versionUUID));

         TransientPropertyData auditVersionName =
            TransientPropertyData.createPropertyData(arNode, EXO_AUDITRECORD_AUDITVERSIONNAME, PropertyType.STRING,
               false, new TransientValueData(versionName.toString()));

         dataManager.update(
            new ItemState(auditVersion, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);
         dataManager.update(
            new ItemState(auditVersionName, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);
      }

      // Update lastRecord
      PropertyData pLastRecord =
         (PropertyData)auditSession.getDataManager().getItemData(
            QPath.makeChildPath(auditHistory.getQPath(), EXO_AUDITHISTORY_LASTRECORD));

      pLastRecord =
         new TransientPropertyData(pLastRecord.getQPath(), pLastRecord.getIdentifier(),
            pLastRecord.getPersistedVersion(), pLastRecord.getType(), pLastRecord.getParentIdentifier(),
            pLastRecord.isMultiValued(), new TransientValueData(String.valueOf(auditRecordName)));

      dataManager.update(
         new ItemState(pLastRecord, ItemState.UPDATED, true, ((ItemImpl)currentItem).getInternalPath()), true);

      if (LOG.isDebugEnabled())
         LOG.debug("Add audit record: " + " Item path="
            + ((ItemImpl)currentItem).getLocation().getInternalPath().getAsString() + " User=" + session.getUserID()
View Full Code Here

   public AuditHistory getHistory(Node node) throws RepositoryException, UnsupportedOperationException
   {

      // get history for this item and create AuditHistory object
      AuditSession auditSession = new AuditSession(node);
      SessionDataManager dm = auditSession.getDataManager();
      NodeData auditHistory = auditSession.getAuditHistoryNodeData();
      if (auditHistory != null)
      {

         List<AuditRecord> auditRecords = new ArrayList<AuditRecord>();
         // AuditRecord aRecord = null;
         ValueFactoryImpl vf = (ValueFactoryImpl)node.getSession().getValueFactory();
         // Search all auditRecords
         List<NodeData> auditRecordsNodeData = dm.getChildNodesData(auditHistory);
         for (NodeData nodeData : auditRecordsNodeData)
         {
            // Searching properties
            List<PropertyData> auditRecordNodeData = dm.getChildPropertiesData(nodeData);
            // define variables
            String user = null;
            InternalQName propertyName = null;
            Value[] oldValue = null;
            Value[] newValue = null;
View Full Code Here

      checkIfAuditable(currentItem);

      AuditSession auditSession = new AuditSession(currentItem);
      SessionImpl session = (SessionImpl)currentItem.getSession();

      SessionDataManager dataManager = auditSession.getDataManager();

      NodeData auditHistory = auditSession.getAuditHistoryNodeData();
      if (auditHistory == null)
         throw new PathNotFoundException("Audit history not found for " + currentItem.getPath());

      if (auditHistory == null)
      {
         throw new RepositoryException("Audit history for " + currentItem.getPath() + "not found");
      }

      // make path to the AUDITHISTORY_LASTRECORD property
      QPath path = QPath.makeChildPath(auditHistory.getQPath(), AuditService.EXO_AUDITHISTORY_LASTRECORD);
      // searching last name of node
      PropertyData pData = (PropertyData)dataManager.getItemData(path);
      String auditRecordName;
      try
      {
         auditRecordName = String.valueOf((int)ValueDataConvertor.readLong(pData.getValues().get(0)) + 1);
      }
      catch (IOException e)
      {
         throw new RepositoryException("Error on add audit record. Problem in calculating new record name. "
            + e.getLocalizedMessage());
      }

      // exo:auditRecord
      List<AccessControlEntry> access = new ArrayList<AccessControlEntry>();
      access.add(new AccessControlEntry(SystemIdentity.ANY, PermissionType.SET_PROPERTY));
      access.add(new AccessControlEntry(SystemIdentity.ANY, PermissionType.READ));

      for (String identity : adminIdentitys)
      {
         access.add(new AccessControlEntry(identity, PermissionType.REMOVE));
      }

      AccessControlList exoAuditRecordAccessControlList = new AccessControlList(session.getUserID(), access);

      TransientNodeData arNode =
         new TransientNodeData(QPath.makeChildPath(auditHistory.getQPath(), new InternalQName(null, auditRecordName)),
            IdGenerator.generate(), -1, AuditService.EXO_AUDITRECORD, new InternalQName[0],
            Integer.parseInt(auditRecordName), auditHistory.getIdentifier(), exoAuditRecordAccessControlList);

      // exo:auditRecord
      dataManager.update(new ItemState(arNode, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);

      // jcr:primaryType
      TransientPropertyData arPrType =
         TransientPropertyData.createPropertyData(arNode, Constants.JCR_PRIMARYTYPE, PropertyType.NAME, false,
            new TransientValueData(arNode.getPrimaryTypeName()));
      // exo:user
      TransientPropertyData arUser =
         TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_USER, PropertyType.STRING,
            false, new TransientValueData(session.getUserID()));
      // exo:created
      TransientPropertyData arCreated =
         TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_CREATED, PropertyType.DATE,
            false, new TransientValueData(dataManager.getTransactManager().getStorageDataManager().getCurrentTime()));
      // exo:eventType
      TransientPropertyData arEventType =
         TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_EVENTTYPE, PropertyType.LONG,
            false, new TransientValueData(eventType));

      // jcr:primaryType
      dataManager.update(new ItemState(arPrType, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()),
         true);

      // exo:user
      dataManager.update(new ItemState(arUser, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);

      // exo:created
      dataManager.update(new ItemState(arCreated, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()),
         true);

      // exo:eventType
      dataManager.update(new ItemState(arEventType, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()),
         true);

      if (!currentItem.isNode())
      {
         int propertyType = ((Property)currentItem).getType();

         if (propertyType != PropertyType.BINARY)
         {

            // exo:newValue
            TransientPropertyData arNewValue =
               TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_NEWVALUE, propertyType,
                  ((PropertyImpl)currentItem).isMultiValued(),
                  ((PropertyData)((PropertyImpl)currentItem).getData()).getValues());

            dataManager.update(
               new ItemState(arNewValue, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);

            if (eventType == Event.PROPERTY_CHANGED)
            {

               // exo:oldValue
               TransientPropertyData arOldValue =
                  TransientPropertyData.createPropertyData(arNode, AuditService.EXO_AUDITRECORD_OLDVALUE, propertyType,
                     ((PropertyImpl)previousItem).isMultiValued(),
                     ((PropertyData)((PropertyImpl)previousItem).getData()).getValues());

               dataManager.update(
                  new ItemState(arOldValue, ItemState.ADDED, true, ((ItemImpl)previousItem).getInternalPath()), true);
            }
         }
      }

      NodeData vancestor; // nearest versionable ancestor
      if (currentItem.isNode())
      {
         vancestor = ((NodeImpl)currentItem).getVersionableAncestor();
      }
      else
      {
         vancestor = ((NodeImpl)((Property)currentItem).getParent()).getVersionableAncestor();

         // exo:propertyName
         TransientPropertyData propertyNameData =
            TransientPropertyData.createPropertyData(arNode, EXO_AUDITRECORD_PROPERTYNAME, PropertyType.STRING, false,
               new TransientValueData(((ItemImpl)currentItem).getInternalName()));
         dataManager.update(
            new ItemState(propertyNameData, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);
      }

      if (vancestor != null)
      {
         // auditable node under a version control, set related properties to the
         // audit record

         String versionUUID; // current base version UUID
         StringBuilder versionName = new StringBuilder(); // current base version name + labels

         PropertyData bvProp =
            (PropertyData)dataManager.getItemData(vancestor, new QPathEntry(Constants.JCR_BASEVERSION, 1),
               ItemType.PROPERTY);
         try
         {
            versionUUID = ValueDataConvertor.readString(bvProp.getValues().get(0));

            // using JCR API objects
            Version version = (Version)dataManager.getItemByIdentifier(versionUUID, false);
            versionName = new StringBuilder(version.getName());

            if (!dataManager.isNew(version.getParent().getUUID()))
            {
               VersionHistory versionHistory =
               (VersionHistory)dataManager.getItemByIdentifier(version.getParent().getUUID(), false);
               String[] labels = versionHistory.getVersionLabels(version);
               for (int i = 0; i < labels.length; i++)
               {
                  String vl = labels[i];
                  if (i == 0)
                  {
                     versionName.append(" ");
                  }
                  versionName.append("'").append(vl).append("' ");
               }
            }
         }
         catch (IOException e)
         {
            throw new RepositoryException("Can't read jcr:baseVersion property, error " + e, e);
         }

         TransientPropertyData auditVersion =
            TransientPropertyData.createPropertyData(arNode, EXO_AUDITRECORD_AUDITVERSION, PropertyType.STRING, false,
               new TransientValueData(versionUUID));

         TransientPropertyData auditVersionName =
            TransientPropertyData.createPropertyData(arNode, EXO_AUDITRECORD_AUDITVERSIONNAME, PropertyType.STRING,
               false, new TransientValueData(versionName.toString()));

         dataManager.update(
            new ItemState(auditVersion, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);
         dataManager.update(
            new ItemState(auditVersionName, ItemState.ADDED, true, ((ItemImpl)currentItem).getInternalPath()), true);
      }

      // Update lastRecord
      PropertyData pLastRecord =
         (PropertyData)auditSession.getDataManager().getItemData(
            QPath.makeChildPath(auditHistory.getQPath(), EXO_AUDITHISTORY_LASTRECORD));

      pLastRecord =
         new TransientPropertyData(pLastRecord.getQPath(), pLastRecord.getIdentifier(),
            pLastRecord.getPersistedVersion(), pLastRecord.getType(), pLastRecord.getParentIdentifier(),
            pLastRecord.isMultiValued(), new TransientValueData(String.valueOf(auditRecordName)));

      dataManager.update(
         new ItemState(pLastRecord, ItemState.UPDATED, true, ((ItemImpl)currentItem).getInternalPath()), true);

      if (LOG.isDebugEnabled())
         LOG.debug("Add audit record: " + " Item path="
            + ((ItemImpl)currentItem).getLocation().getInternalPath().getAsString() + " User=" + session.getUserID()
View Full Code Here

   public AuditHistory getHistory(Node node) throws RepositoryException, UnsupportedOperationException
   {

      // get history for this item and create AuditHistory object
      AuditSession auditSession = new AuditSession(node);
      SessionDataManager dm = auditSession.getDataManager();
      NodeData auditHistory = auditSession.getAuditHistoryNodeData();
      if (auditHistory != null)
      {

         List<AuditRecord> auditRecords = new ArrayList<AuditRecord>();
         // AuditRecord aRecord = null;
         ValueFactoryImpl vf = (ValueFactoryImpl)node.getSession().getValueFactory();
         // Search all auditRecords
         List<NodeData> auditRecordsNodeData = dm.getChildNodesData(auditHistory);
         for (NodeData nodeData : auditRecordsNodeData)
         {
            // Searching properties
            List<PropertyData> auditRecordNodeData = dm.getChildPropertiesData(nodeData);
            // define variables
            String user = null;
            InternalQName propertyName = null;
            Value[] oldValue = null;
            Value[] newValue = null;
View Full Code Here

         {
            // for each child node of n' in D' copy it (and its subtree) to n
            // as a new child node (if an incoming node has the same
            // UUID as a node already existing in this workspace,
            // the already existing node is removed).
            SessionDataManager mergeDataManager = mergeSession.getTransientNodesManager();
            for (NodeData corrNode : context.getCorrChildNodes())
            {
               NodeData existedSameIdentifier = (NodeData)mergeDataManager.getItemData(corrNode.getIdentifier());
               if (existedSameIdentifier != null)
               {
                  // if an incoming node has the same
                  // UUID as a node already existing in this workspace,
                  // the already existing node is removed
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.core.SessionDataManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.