Exemple #1
0
        private void deleteReference(Alfresco.RepositoryWebService.Reference reference)
        {
            Alfresco.RepositoryWebService.Predicate where = new Alfresco.RepositoryWebService.Predicate();
            where.Items = new Alfresco.RepositoryWebService.Reference[] { reference };

            CMLDelete cmlDelete = new CMLDelete();

            cmlDelete.where = where;

            CML cml = new CML();

            cml.delete = new CMLDelete[] { cmlDelete };
            this.repoService.update(cml);
        }
Exemple #2
0
        private CML getCMLUpdate(String uuid, NamedValue[] properties)
        {
            // ************ test ***********8

            /*
             * for (int i = 0; i < properties.Length; i++)
             * {
             *
             *  NamedValue name = properties[i];
             *  if (name.name.Equals(Alfresco.Constants.PROP_DESCRIPTION))
             *  {
             *      MessageBox.Show("Gotcha");
             *      name.value = "UPDATE";
             *      properties[i] = name;
             *  }
             * }
             */

            Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference();
            reference.store = this.spacesStore;
            reference.uuid  = uuid;

            CMLUpdate cmlUpdate = new CMLUpdate();

            Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate();
            pred.Items         = new Alfresco.RepositoryWebService.Reference[] { reference };
            cmlUpdate.where    = pred;
            cmlUpdate.property = properties;

            // Create and execute the cml statement
            CML cml = new CML();

            cml.update = new CMLUpdate[] { cmlUpdate };

            return(cml);
        }
        public void CanUpdateNodes()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore");
            String name = "AWS Book - Remove Child " + DateTime.Now.Ticks;
            String spaceNameForMove = "AWS Book - Remove Child Space Sample " + DateTime.Now.Ticks;
            String description = "This is a content created with a sample of the book";

            //custom value object
            CreateSampleVO createSampleVo = Builder.BuildCreateSampleVO(name, name, description);
            CreateSampleVO createFolderSampleVo = Builder.BuildCreateSampleVO(spaceNameForMove, spaceNameForMove, description);

            try
            {

                //parent for the new node
                ParentReference parentForNode = new ParentReference(
                        spacesStore,
                        null,
                        "/app:company_home",
                        Constants.ASSOC_CONTAINS,
                        "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + name
                );

                //parent for the new space
                ParentReference parentForSpace = new ParentReference(
                        spacesStore,
                        null,
                        "/app:company_home",
                        Constants.ASSOC_CONTAINS,
                        "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + spaceNameForMove
                );

                //build properties
                NamedValue[] properties = Builder.BuildCustomProperties(createSampleVo);
                NamedValue[] propertiesForSpace = Builder.BuildCustomPropertiesForSpace(createFolderSampleVo);

                //create a node
                CMLCreate create = new CMLCreate();
                create.id = "1";
                create.parent = parentForNode;
                create.type = Constants.TYPE_CONTENT;
                create.property = properties;

                //create a space
                CMLCreate createSpace = new CMLCreate();
                createSpace.id = "2";
                createSpace.parent = parentForSpace;
                createSpace.type = Constants.TYPE_FOLDER;
                createSpace.property = propertiesForSpace;

                //build the CML object
                CML cmlAdd = new CML();
                cmlAdd.create = new CMLCreate[] { create, createSpace };

                //perform a CML update to create nodes
                UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cmlAdd);

                String expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath));

                expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_Space_x0020_Sample_x0020_";
                Assert.IsTrue(result[1].destination.path.StartsWith(expectedPath));

                //create a predicate with the first CMLCreate result
                Reference referenceForNode = result[0].destination;
                Predicate sourcePredicate = new Predicate(new Reference[] { referenceForNode }, spacesStore, null);

                //create a reference from the second CMLCreate performed for space
                Reference referenceForTargetSpace = result[1].destination;

                //reference for the target space
                ParentReference targetSpace = new ParentReference();
                targetSpace.store = spacesStore;
                targetSpace.path = referenceForTargetSpace.path;
                targetSpace.associationType = Constants.ASSOC_CONTAINS;
                targetSpace.childName = name;

                name = "AWS Book - Changed by CMLUpdate " + DateTime.Now.Ticks;
                createSampleVo.Name = name;
                createSampleVo.Title = name;
                createSampleVo.Description = "Changed by CMLUpdate " + description;

                //add versionable aspect to the node
                CMLAddAspect aspect = new CMLAddAspect();
                aspect.aspect = Constants.ASPECT_VERSIONABLE;
                aspect.where = sourcePredicate;

                //update node
                CMLUpdate update = new CMLUpdate();
                update.property = Builder.BuildCustomProperties(createSampleVo);
                update.where = sourcePredicate;

                CML cmlUpdate = new CML();
                cmlUpdate.addAspect = new CMLAddAspect[] { aspect };
                cmlUpdate.update = new CMLUpdate[] { update };

                //perform a CML update
                WebServiceFactory.getRepositoryService().update(cmlUpdate);

                expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_-_x0020_Remove_x0020_Child_x0020_";
                Reference firtItem = sourcePredicate.Items[0] as Reference;
                Assert.IsTrue(firtItem.path.StartsWith(expectedPath));

            }
            finally
            {
                AuthenticationUtils.endSession();
            }
        }
        private CML getCMLUpdate(String uuid, NamedValue[] properties)
        {
            // ************ test ***********8
            /*
            for (int i = 0; i < properties.Length; i++)
            {

                NamedValue name = properties[i];
                if (name.name.Equals(Alfresco.Constants.PROP_DESCRIPTION))
                {
                    MessageBox.Show("Gotcha");
                    name.value = "UPDATE";
                    properties[i] = name;
                }
            }
            */

            Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference();
            reference.store = this.spacesStore;
            reference.uuid = uuid;

            CMLUpdate cmlUpdate = new CMLUpdate();
            Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate();
            pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference };
            cmlUpdate.where = pred;
            cmlUpdate.property = properties;

            // Create and execute the cml statement
            CML cml = new CML();
            cml.update = new CMLUpdate[] { cmlUpdate };

            return cml;
        }
        private void deleteReference(Alfresco.RepositoryWebService.Reference reference)
        {
            Alfresco.RepositoryWebService.Predicate where = new Alfresco.RepositoryWebService.Predicate();
            where.Items = new Alfresco.RepositoryWebService.Reference[] { reference };

            CMLDelete cmlDelete = new CMLDelete();
            cmlDelete.where = where;

            CML cml = new CML();
            cml.delete = new CMLDelete[] { cmlDelete };
            this.repoService.update(cml);
        }
        //**********************************************************
        // Function:	ReleaseDoc()
        // Scope:		internal
        // Overview:	Document release point.  Use the ReleaseData
        //                object to release the current document's data
        //                to the external data source.
        // Params:		none
        // Returns:		One of the following: KFX_REL_SUCCESS,
        //                KFX_REL_ERROR, KFX_REL_DOCCLASSERROR,
        //                KFX_REL_QUEUED
        // Called By:	The Batch Release Manager.  Called once for each
        //                document to be released.
        //**********************************************************
        public AscentRelease.KfxReturnValue ReleaseDoc()
        {
            try
            {

                String name = ReleaseUtils.getLinkValue(this.releaseData.Values, ReleaseConstants.CONTENT_TYPE + Alfresco.Constants.PROP_NAME);
                if (name == null || name.Equals(""))
                {
                    // node name is null or ""
                    Log log = new Log();
                    log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc - Content name is empty, check index fields in Release setup or the Content Type properties in Alfresco", "");
                    return AscentRelease.KfxReturnValue.KFX_REL_ERROR;
                }
                String location = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION);

                // get properties and aspects list
                int i = 0;
                ArrayList aspectFields = new ArrayList();
                ArrayList properties = new ArrayList();
                NamedValue nameValue = new NamedValue();
                // if its a content type field then create a NamedValue otherwise
                // store in the aspect array to be used later on
                foreach (AscentRelease.Value oValue in releaseData.Values)
                {

                    String value = oValue.Value;
                    String destination = oValue.Destination;
                    if (destination.StartsWith(ReleaseConstants.CONTENT_TYPE))
                    {
                        // content type field
                        nameValue = new NamedValue();

                        // need to remove the prefix
                        int start = ReleaseConstants.CONTENT_TYPE.Length;
                        nameValue.name = destination.Substring(start, (destination.Length - start));
                        nameValue.value = value;
                        nameValue.isMultiValue = false;
                        properties.Add(nameValue);
                    }
                    else
                    {
                        // aspect field
                        aspectFields.Add(oValue);
                    }
                }

                // create the CML
                bool isNew = true;
                String existingUuid = this.getNodeUuidFromLocation(this.locationUuid, name);
                CML cml;

                // flag to delete refnode if there is an error uploading the content
                bool deleteOnErrFlag = true;
                if (existingUuid.Equals(""))
                {
                    // new content to upload
                    cml = this.getCMLCreate((NamedValue[])properties.ToArray(typeof(NamedValue)));
                }
                else
                {
                    // update, set deleteFlag to false for updating node Content
                    deleteOnErrFlag = false;
                    cml = this.getCMLUpdate(existingUuid, (NamedValue[])properties.ToArray(typeof(NamedValue)));
                    isNew = false;

                }

                // create any aspects
                CMLAddAspect[] cmlAspects = null;
                String aspects = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_ASPECTS);
                AscentRelease.Value aspectValue;
                if (aspects != null)
                {
                    // seperate the aspects string
                    String[] aspectNames = ReleaseUtils.SplitByString(aspects, ReleaseConstants.SEPERATOR);
                    String aspectName;

                    cmlAspects = new CMLAddAspect[aspectNames.Length];
                    // for each aspect create a aspect CML
                    for (i = 0; i < aspectNames.Length; i++)
                    {
                        aspectName = aspectNames[i];

                        // create the aspect CML
                        CMLAddAspect addAspect = new CMLAddAspect();

                        addAspect.aspect = aspectName;

                        if (isNew)
                        {
                            addAspect.where_id = "1";
                        }
                        else
                        {
                            // use  predicate

                            Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference();
                            reference.store = this.spacesStore;
                            reference.uuid = existingUuid;

                            Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate();
                            pred.Items = new Alfresco.RepositoryWebService.Reference[] { reference };
                            addAspect.where = pred;
                        }

                        ArrayList aspectProperties = new ArrayList();
                        // add the aspect fields for this aspect
                        for (int j = 0; j < aspectFields.Count; j++)
                        {
                            // loop thru the aspects fields and add the relevent fields
                            aspectValue = (AscentRelease.Value)aspectFields[j];
                            String destination = aspectValue.Destination;

                            String prefix = ReleaseConstants.ASPECT + ReleaseConstants.SEPERATOR + aspectName;

                            if (destination.StartsWith(prefix))
                            {
                                // content type field
                                nameValue = new NamedValue();

                                // need to remove the prefix
                                int start = prefix.Length;
                                nameValue.name = destination.Substring(start, (destination.Length - start));
                                nameValue.value = aspectValue.Value;
                                nameValue.isMultiValue = false;
                                aspectProperties.Add(nameValue);

                            }
                        }
                        addAspect.property = (NamedValue[])aspectProperties.ToArray(typeof(NamedValue));
                        cmlAspects[i] = addAspect;
                    }
                }

                // add any aspects
                if (cmlAspects != null && cmlAspects.Length > 0)
                {
                    cml.addAspect = cmlAspects;
                }

                UpdateResult[] updateResult = this.repoService.update(cml);

                if (!this.writeNewContent(updateResult[0].destination, deleteOnErrFlag))
                {
                    // failed to update content, deleted
                    return AscentRelease.KfxReturnValue.KFX_REL_ERROR;
                }

                return AscentRelease.KfxReturnValue.KFX_REL_SUCCESS;

            }
            catch (Exception e)
            {
                Log log = new Log();
                log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc " + e.Message, e.StackTrace);

                return AscentRelease.KfxReturnValue.KFX_REL_ERROR;
            }
        }
 public NodeDefinition[] describe(Predicate items)
 {
     object[] results = this.Invoke("describe", new object[] {
                 items});
     return ((NodeDefinition[])(results[0]));
 }
 /// <remarks/>
 public System.IAsyncResult Beginget(Predicate @where, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("get", new object[] {
                 @where}, callback, asyncState);
 }
 /// <remarks/>
 public System.IAsyncResult Begindescribe(Predicate items, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("describe", new object[] {
                 items}, callback, asyncState);
 }
 public Node[] get(Predicate @where)
 {
     object[] results = this.Invoke("get", new object[] {
                 @where});
     return ((Node[])(results[0]));
 }
        public void CanCreateNodesWithContent()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore");
            String name = "AWSBook " + DateTime.Now.Ticks;
            String description = "This is a content created with a sample of the book";
            String mimeType = "text/plain";
            String encoding = "UTF-8";

            //custom value object
            CreateSampleVO createSampleVo = Builder.BuildCreateSampleVO(name, name, description);

            try {

                ParentReference parent = new ParentReference(
                        spacesStore,
                        null,
                        "/app:company_home",
                        Constants.ASSOC_CONTAINS,
                        "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + name
                );

                //build properties
                NamedValue[] properties = Builder.BuildCustomProperties(createSampleVo);

                //create operation
                CMLCreate create = new CMLCreate();
                create.id = "1";
                create.parent = parent;
                create.type = Constants.TYPE_CONTENT;
                create.property = properties;

                //create the node reference
                Reference reference = new Reference();
                reference.store = spacesStore;
                reference.path = "/app:company_home/cm:" + ISO9075.Encode(name);

                //create the predicate
                Predicate predicate = new Predicate();
                predicate.Items = new Reference[]{ reference };

                //set mime type and encoding for indexing
                ContentFormat format = new ContentFormat(mimeType, encoding);

                //write operation
                CMLWriteContent writeContent = new CMLWriteContent();
                writeContent.format = format;
                writeContent.where = predicate;
                writeContent.property = Constants.PROP_CONTENT;
                writeContent.content = new ASCIIEncoding().GetBytes("This is the content for the new node");

                //build the CML object
                CML cml = new CML();
                cml.create = new CMLCreate[]{ create };
                cml.writeContent = new CMLWriteContent[]{ writeContent };

                //perform a complete CML update for the node and the related file
                UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);

                String expectedPath = "/app:company_home/cm:AWSBook_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath));

            } finally {
                AuthenticationUtils.endSession();
            }
        }
        public void CanDeleteNodes()
        {
            AuthenticationUtils.startSession("admin", "admin");
            Store spacesStore = new Store(StoreEnum.workspace, "SpacesStore");
            String name = "AWS Book " + DateTime.Now.Ticks;
            String description = "This is a content created with a sample of the book";

            //custom value object
            CreateSampleVO createSampleVo = Builder.BuildCreateSampleVO(name, name, description);

            try {

                ParentReference parent = new ParentReference(
                        spacesStore,
                        null,
                        "/app:company_home",
                        Constants.ASSOC_CONTAINS,
                        "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + name
                );

                //build properties
                NamedValue[] properties = Builder.BuildCustomProperties(createSampleVo);

                //create operation
                CMLCreate create = new CMLCreate();
                create.id = "1";
                create.parent = parent;
                create.type = Constants.TYPE_CONTENT;
                create.property = properties;

                //build the CML object
                CML cmlAdd = new CML();
                cmlAdd.create = new CMLCreate[]{create};

                //perform a CML update to create the node
                UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cmlAdd);

                String expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_";
                Assert.IsTrue(result[0].destination.path.StartsWith(expectedPath));

                //create a predicate
                Reference reference = result[0].destination;
                Predicate predicate = new Predicate(new Reference[]{ reference }, spacesStore, null);

                //delete content
                CMLDelete delete = new CMLDelete();
                delete.where = predicate;

                CML cmlRemove = new CML();
                cmlRemove.delete = new CMLDelete[]{delete};

                //perform a CML update to remove the node
                WebServiceFactory.getRepositoryService().update(cmlRemove);

                expectedPath = "/app:company_home/cm:AWS_x0020_Book_x0020_";
                Assert.IsTrue(reference.path.StartsWith(expectedPath));

            } finally {
                AuthenticationUtils.endSession();
            }
        }
Exemple #13
0
        //**********************************************************
        // Function:	ReleaseDoc()
        // Scope:		internal
        // Overview:	Document release point.  Use the ReleaseData
        //				object to release the current document's data
        //				to the external data source.
        // Params:		none
        // Returns:		One of the following: KFX_REL_SUCCESS,
        //				KFX_REL_ERROR, KFX_REL_DOCCLASSERROR,
        //				KFX_REL_QUEUED
        // Called By:	The Batch Release Manager.  Called once for each
        //				document to be released.
        //**********************************************************
        public AscentRelease.KfxReturnValue ReleaseDoc()
        {
            try
            {
                String name = ReleaseUtils.getLinkValue(this.releaseData.Values, ReleaseConstants.CONTENT_TYPE + Alfresco.Constants.PROP_NAME);
                if (name == null || name.Equals(""))
                {
                    // node name is null or ""
                    Log log = new Log();
                    log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc - Content name is empty, check index fields in Release setup or the Content Type properties in Alfresco", "");
                    return(AscentRelease.KfxReturnValue.KFX_REL_ERROR);
                }
                String location = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION);

                // get properties and aspects list
                int        i            = 0;
                ArrayList  aspectFields = new ArrayList();
                ArrayList  properties   = new ArrayList();
                NamedValue nameValue    = new NamedValue();
                // if its a content type field then create a NamedValue otherwise
                // store in the aspect array to be used later on
                foreach (AscentRelease.Value oValue in releaseData.Values)
                {
                    String value       = oValue.Value;
                    String destination = oValue.Destination;
                    if (destination.StartsWith(ReleaseConstants.CONTENT_TYPE))
                    {
                        // content type field
                        nameValue = new NamedValue();

                        // need to remove the prefix
                        int start = ReleaseConstants.CONTENT_TYPE.Length;
                        nameValue.name         = destination.Substring(start, (destination.Length - start));
                        nameValue.value        = value;
                        nameValue.isMultiValue = false;
                        properties.Add(nameValue);
                    }
                    else
                    {
                        // aspect field
                        aspectFields.Add(oValue);
                    }
                }

                // create the CML
                bool   isNew        = true;
                String existingUuid = this.getNodeUuidFromLocation(this.locationUuid, name);
                CML    cml;

                // flag to delete refnode if there is an error uploading the content
                bool deleteOnErrFlag = true;
                if (existingUuid.Equals(""))
                {
                    // new content to upload
                    cml = this.getCMLCreate((NamedValue[])properties.ToArray(typeof(NamedValue)));
                }
                else
                {
                    // update, set deleteFlag to false for updating node Content
                    deleteOnErrFlag = false;
                    cml             = this.getCMLUpdate(existingUuid, (NamedValue[])properties.ToArray(typeof(NamedValue)));
                    isNew           = false;
                }

                // create any aspects
                CMLAddAspect[]      cmlAspects = null;
                String              aspects    = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_ASPECTS);
                AscentRelease.Value aspectValue;
                if (aspects != null)
                {
                    // seperate the aspects string
                    String[] aspectNames = ReleaseUtils.SplitByString(aspects, ReleaseConstants.SEPERATOR);
                    String   aspectName;

                    cmlAspects = new CMLAddAspect[aspectNames.Length];
                    // for each aspect create a aspect CML
                    for (i = 0; i < aspectNames.Length; i++)
                    {
                        aspectName = aspectNames[i];

                        // create the aspect CML
                        CMLAddAspect addAspect = new CMLAddAspect();

                        addAspect.aspect = aspectName;

                        if (isNew)
                        {
                            addAspect.where_id = "1";
                        }
                        else
                        {
                            // use  predicate

                            Alfresco.RepositoryWebService.Reference reference = new Alfresco.RepositoryWebService.Reference();
                            reference.store = this.spacesStore;
                            reference.uuid  = existingUuid;

                            Alfresco.RepositoryWebService.Predicate pred = new Alfresco.RepositoryWebService.Predicate();
                            pred.Items      = new Alfresco.RepositoryWebService.Reference[] { reference };
                            addAspect.where = pred;
                        }

                        ArrayList aspectProperties = new ArrayList();
                        // add the aspect fields for this aspect
                        for (int j = 0; j < aspectFields.Count; j++)
                        {
                            // loop thru the aspects fields and add the relevent fields
                            aspectValue = (AscentRelease.Value)aspectFields[j];
                            String destination = aspectValue.Destination;

                            String prefix = ReleaseConstants.ASPECT + ReleaseConstants.SEPERATOR + aspectName;

                            if (destination.StartsWith(prefix))
                            {
                                // content type field
                                nameValue = new NamedValue();

                                // need to remove the prefix
                                int start = prefix.Length;
                                nameValue.name         = destination.Substring(start, (destination.Length - start));
                                nameValue.value        = aspectValue.Value;
                                nameValue.isMultiValue = false;
                                aspectProperties.Add(nameValue);
                            }
                        }
                        addAspect.property = (NamedValue[])aspectProperties.ToArray(typeof(NamedValue));
                        cmlAspects[i]      = addAspect;
                    }
                }

                // add any aspects
                if (cmlAspects != null && cmlAspects.Length > 0)
                {
                    cml.addAspect = cmlAspects;
                }

                UpdateResult[] updateResult = this.repoService.update(cml);

                if (!this.writeNewContent(updateResult[0].destination, deleteOnErrFlag))
                {
                    // failed to update content, deleted
                    return(AscentRelease.KfxReturnValue.KFX_REL_ERROR);
                }

                return(AscentRelease.KfxReturnValue.KFX_REL_SUCCESS);
            }
            catch (Exception e)
            {
                Log log = new Log();
                log.ErrorLog(".\\log\\", "KfxReleaseScript method ReleaseDoc " + e.Message, e.StackTrace);

                return(AscentRelease.KfxReturnValue.KFX_REL_ERROR);
            }
        }