Exemple #1
0
        //**********************************************************
        // Function:	OpenScript()
        // Scope:		internal
        // Overview:	Script initialization point.  Perform any
        //				necessary initialization such as logging
        //				in to a remote data source, allocated any
        //				necessary resources, etc.
        // Params:		none
        // Returns:		One of the following:
        //				KFX_REL_SUCCESS, KFX_REL_ERROR
        // Called By:	The Batch Release Manager.  Called once
        //				when the script object is loaded.
        //**********************************************************
        public AscentRelease.KfxReturnValue OpenScript()
        {
            // Start the Alfresco session
            try
            {
                string repository = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_REPOSITORY);
                WebServiceFactory.setEndpointAddress(repository);

                string userName = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_USERNAME);
                string password = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_PASSWORD);
                AuthenticationUtils.startSession(userName, password);
                this.repoService = WebServiceFactory.getRepositoryService();

                // the uuid of the location to be saved
                this.locationUuid = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_LOCATION_UUID);

                this.contentType = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_CONTENT_TYPE);

                this.imageContentProp = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_IMAGE);
                this.ocrContentProp   = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_OCR);
                this.pdfContentProp   = ReleaseUtils.getCustomProperty(this.releaseData.CustomProperties, ReleaseConstants.CUSTOM_PDF);

                // Initialise the reference to the spaces store
                this.spacesStore    = new Alfresco.RepositoryWebService.Store();
                spacesStore.scheme  = Alfresco.RepositoryWebService.StoreEnum.workspace;
                spacesStore.address = "SpacesStore";

                return(AscentRelease.KfxReturnValue.KFX_REL_SUCCESS);
            }
            catch (Exception)
            {
                return(AscentRelease.KfxReturnValue.KFX_REL_ERROR);
            }
        }
Exemple #2
0
        //*********************************************************
        // Function:	ActionEvent()
        // Scope:		internal
        // Overview:	Called by the setup controller to invoke a specific
        //				action for the script to respond to.
        //				Refer to the documentation for a list of actions and
        //				their associated parameters.
        // Params:		ActionID - ID of the action to perform
        //				strData1 - Action parameter 1
        //				strData2 - Action parameter 2
        // Returns:		One of the following:
        //				KFX_REL_SUCCESS, KFX_REL_ERROR, KFX_REL_STOPPED
        // Called By:	Called once by the Release Setup Controller to perform
        //**********************************************************
        public KfxReturnValue ActionEvent(AscentRelease.KfxActionValue oActionID, string strData1, string strData2)
        {
            try
            {
                switch (oActionID)
                {
                case KfxActionValue.KFX_REL_BATCHCLASS_RENAME:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_BATCHFIELD_DELETE:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_BATCHFIELD_INSERT:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_BATCHFIELD_RENAME:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_DOCCLASS_RENAME:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_END:
                {
                    //Last action event fired. Handle showing UI if necessary.
                    if (showUI)
                    {
                        RunUI();
                    }

                    break;
                }

                case KfxActionValue.KFX_REL_IMPORT:
                {
                    RunUI();

                    break;
                }

                case KfxActionValue.KFX_REL_INDEXFIELD_DELETE:
                {
                    showUI = ReleaseUtils.OnIndexFieldDelete(strData1, releaseSetUpData);

                    break;
                }

                case KfxActionValue.KFX_REL_INDEXFIELD_INSERT:
                {
                    showUI = true;
                    break;
                }

                case KfxActionValue.KFX_REL_INDEXFIELD_RENAME:
                {
                    ReleaseUtils.OnIndexFieldRename(strData1, strData2, releaseSetUpData);
                    break;
                }

                case KfxActionValue.KFX_REL_PUBLISH_CHECK:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_RELEASESETUP_DELETE:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_START:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_UNDEFINED_ACTION:
                {
                    break;
                }

                case KfxActionValue.KFX_REL_UPGRADE:
                {
                    return(AscentRelease.KfxReturnValue.KFX_REL_UNSUPPORTED);
                }

                default:
                {
                    break;
                }
                }

                return(AscentRelease.KfxReturnValue.KFX_REL_SUCCESS);
            }
            catch (Exception e)
            {
                return(AscentRelease.KfxReturnValue.KFX_REL_ERROR);
            }
        }
Exemple #3
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);
            }
        }