Esempio n. 1
0
        /// <summary>
        /// Edits a specific requirement by its id
        /// </summary>
        /// <param name="requirementName">The name of the requirement which should be deleted</param>
        /// /// <param name="projectId">The id of the project of the requirement which should be deleted</param>
        /// <returns>The deleted requirement</returns>
        public static async Task <Requirement> EditRequirement(int requirementId, int projectId, string newName, string newDescription)
        {
            Requirement[] projectRequirements = await GetProjectRequirements(projectId);

            Requirement requirement = null;

            for (int i = 0; i < projectRequirements.Length; i++)
            {
                if (projectRequirements[i].Id == requirementId)
                {
                    requirement = projectRequirements[i];
                    break;
                }
            }
            if (requirement == null)
            {
                Debug.LogError("Requirement not found");
                return(null);
            }

            //Editing the requirement
            requirement.Name        = newName;
            requirement.Description = newDescription;


            string url = baseUrl + "requirements/" + requirement.Id;

            // convert the requirement to a uploadable format (the statistic fields of the requirement are not recognized as input by the service)
            UploadableRequirement uploadableRequirement = requirement.ToUploadFormat();

            string json = JsonUtility.ToJson(uploadableRequirement);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            if (ServiceManager.GetService <LearningLayersOidcService>() != null)
            {
                Debug.Log("Service not null");
            }
            headers.Add("Authorization", "Bearer " + ServiceManager.GetService <LearningLayersOidcService>().AccessToken);

            Response response = await Rest.PutAsync(url, json, headers, -1, true);

            if (!response.Successful)
            {
                Debug.LogError(response.ResponseCode + ": " + response.ResponseBody);
                return(null);
            }
            else
            {
                Requirement updatedRequirement = JsonUtility.FromJson <Requirement>(response.ResponseBody);
                return(updatedRequirement);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the specified requirement
        /// Please first query for the requirement to change, then changing its parameters and then supply it to this function
        /// </summary>
        /// <param name="toUpdate">The requirement to update</param>
        /// <returns>The updated requirement</returns>
        public static async Task <Requirement> UpdateRequirement(Requirement toUpdate)
        {
            string url = baseUrl + "requirements/" + toUpdate.Id;

            // convert the requirement to a uploadable format (the statistic fields of the requirement are not recognized as input by the service)
            UploadableRequirement uploadableRequirement = toUpdate.ToUploadFormat();

            string json = JsonUtility.ToJson(uploadableRequirement);

            Response response = await Rest.PutAsync(url, json, null, -1, true);

            if (!response.Successful)
            {
                Debug.LogError(response.ResponseCode + ": " + response.ResponseBody);
                return(null);
            }
            else
            {
                Requirement requirement = JsonUtility.FromJson <Requirement>(response.ResponseBody);
                return(requirement);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates and posts a new requirement
        /// </summary>
        /// <param name="projectId">The id of the project where the requirement will be posted</param>
        /// <param name="name">The name/title of the requirement</param>
        /// <param name="description">The description of the requirement</param>
        /// <param name="categories">Categories in the project</param>
        /// <returns>The resulting requirement as it was saved on the server</returns>
        public static async Task <Requirement> CreateRequirement(int projectId, string name, string description, Category[] categories = null)
        {
            string url = baseUrl + "requirements/";

            // check if categories were supplied; if no: look for the default category and it in there
            if (categories == null)
            {
                Project proj = await GetProject(projectId);

                categories    = new Category[1];
                categories[0] = await GetCategory(proj.DefaultCategoryId);
            }

            // convert the requirement to a uploadable format (the statistic fields of the requirement are not recognized as input by the service)
            UploadableRequirement toCreate = new UploadableRequirement(name, description, projectId, categories);

            string json = JsonUtility.ToJson(toCreate);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            if (ServiceManager.GetService <LearningLayersOidcService>() != null)
            {
                Debug.Log("Service not null");
            }
            headers.Add("Authorization", "Bearer " + ServiceManager.GetService <LearningLayersOidcService>().AccessToken);
            Response resp = await Rest.PostAsync(url, json, headers, -1, true);

            if (!resp.Successful)
            {
                Debug.LogError(resp.ResponseCode + ": " + resp.ResponseBody);
                return(null);
            }
            else
            {
                Requirement requirement = JsonUtility.FromJson <Requirement>(resp.ResponseBody);
                return(requirement);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Converts the requirement to a UploadableRequirement
        /// The UploadableRequirement has a format which is accepted by the ReqBaz server when uploading a requirement
        /// </summary>
        /// <returns>The UploadableRequirement which can be serialized and uploaded</returns>
        public UploadableRequirement ToUploadFormat()
        {
            UploadableRequirement req = new UploadableRequirement(id, name, description, projectId, categories);

            return(req);
        }