Exemplo n.º 1
0
        public void CanVersionNodes()
        {
            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);

                //update node version 1.1
                CMLUpdate update11 = new CMLUpdate();
                createSampleVo.Name  = "1.1 " + name;
                createSampleVo.Title = "1.1" + name;
                update11.property    = Builder.BuildCustomProperties(createSampleVo);
                update11.where       = sourcePredicate;

                CML cmlUpdate11 = new CML();
                cmlUpdate11.update = new CMLUpdate[] { update11 };

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

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

                //node history: the 1.0 version
                Alfresco.AuthoringWebService.Reference      reference   = Alfresco.AuthoringWebService.Reference.From(firstItem);
                Alfresco.AuthoringWebService.VersionHistory nodeHistory = WebServiceFactory.getAuthoringService().getVersionHistory(reference);

                Assert.AreEqual(2, nodeHistory.versions.Length);

                Alfresco.AuthoringWebService.Version latestVersion = nodeHistory.versions[0];
                Assert.NotNull(latestVersion.id.uuid);
                Assert.AreEqual("1.1", latestVersion.label);
                Assert.AreEqual(DateTime.Now.Date, latestVersion.created.Date);
                Assert.AreEqual("admin", latestVersion.creator);

                Alfresco.AuthoringWebService.Version previousVersion = nodeHistory.versions[1];
                Assert.NotNull(previousVersion.id.uuid);
                Assert.AreEqual("1.0", previousVersion.label);
                Assert.AreEqual(DateTime.Now.Date, previousVersion.created.Date);
                Assert.AreEqual("admin", previousVersion.creator);
            } finally {
                AuthenticationUtils.endSession();
            }
        }
Exemplo n.º 2
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);
            }
        }