<commit_before>/*
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License.  You may obtain a
 * copy of the License at the following location:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package io.cos.cas.web.flow;

import com.google.gson.Gson;

import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Open Science Framework Login Handler.
 *
 * @author <NAME>
 * @since 4.1.5
 */
public class OpenScienceFrameworkLoginHandler {

    /**
     * Open Science Framework Login Context.
     *
     * @author <NAME>
     * @since  4.1.5
     */
    public static final class OpenScienceFrameworkLoginContext {

        /** The service URL in the context. */
        private String serviceUrl;

        /** The simple name of the authentication exception that just happened. */
        private String handleErrorName;

        /** The flag for institution login instead of normal OSF login. */
        private boolean institutionLogin;

        /** The flag for redirect to ORCiD login instead of normal OSF login. */
        private boolean orcidRedirect;

        /**
         * Construct an instance of `OpenScienceFrameworkLoginContext` with the given settings.
         *
         * @param serviceUrl the service URL
         * @param institutionLogin the flag for institution login
         */
        private OpenScienceFrameworkLoginContext(final String serviceUrl, final boolean institutionLogin) {
            this.serviceUrl = serviceUrl;
            this.handleErrorName = null;
            this.institutionLogin = institutionLogin;
        }

        public String getServiceUrl() {
            return serviceUrl;
        }

        public void setServiceUrl(final String serviceUrl) {
            this.serviceUrl = serviceUrl;
        }

        public String getHandleErrorName() {
            return handleErrorName;
        }

        public void setHandleErrorName(final String handleErrorName) {
            this.handleErrorName =handleErrorName;
        }

        public boolean getInstitutionLogin() {
            return institutionLogin;
        }

        public void setInstitutionLogin(final Boolean institutionLogin) {
            this.institutionLogin = institutionLogin;
        }

        public boolean isOrcidRedirect() {
            return orcidRedirect;
        }

        public void setOrcidRedirect(final boolean orcidRedirect) {
            this.orcidRedirect = orcidRedirect;
        }

        /**
         * Check if the service URL exists.
         *
         * @return true if service url exists, false otherwise
         */
        public boolean isServiceUrl() {
            return serviceUrl != null;
        }

        /**
         * Check if it is institution login.
         *
         * @return true if institution login, false otherwise
         */
        public boolean isInstitutionLogin() {
            return institutionLogin;
        }

        /**
         * Convert the class instance to a JSON string, which will be passed to the flow context.
         *
         * @return JSON string
         */
        public String toJson() {
            final Gson gson = new Gson();
            return gson.toJson(this);
        }

        /**
         * Convert the JSON string to a class instance.
         *
         * @param jsonString a JSON string previously generated by the method .toJson()
         * @return an reconstructed instance of OpenScienceFrameworkLoginContext
         */
        public static OpenScienceFrameworkLoginContext fromJson(final String jsonString) {
            final Gson gson = new Gson();<commit_msg>Fix setter and getter for OSFLoginContext<commit_after>/*
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License.  You may obtain a
 * copy of the License at the following location:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package io.cos.cas.web.flow;

import com.google.gson.Gson;

import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Open Science Framework Login Handler.
 *
 * @author <NAME>
 * @since 4.1.5
 */
public class OpenScienceFrameworkLoginHandler {

    /**
     * Open Science Framework Login Context.
     *
     * @author <NAME>
     * @since  4.1.5
     */
    public static final class OpenScienceFrameworkLoginContext {

        /** The service URL in the context. */
        private String serviceUrl;

        /** The simple name of the authentication exception that just happened. */
        private String handleErrorName;

        /** The flag for institution login instead of normal OSF login. */
        private boolean institutionLogin;

        /** The flag for redirect to ORCiD login instead of normal OSF login. */
        private boolean orcidRedirect;

        /**
         * Construct an instance of `OpenScienceFrameworkLoginContext` with the given settings.
         *
         * @param serviceUrl the service URL
         * @param institutionLogin the flag for institution login
         */
        private OpenScienceFrameworkLoginContext(final String serviceUrl, final boolean institutionLogin) {
            this.serviceUrl = serviceUrl;
            this.handleErrorName = null;
            this.institutionLogin = institutionLogin;
        }

        public String getServiceUrl() {
            return serviceUrl;
        }

        public void setServiceUrl(final String serviceUrl) {
            this.serviceUrl = serviceUrl;
        }

        public String getHandleErrorName() {
            return handleErrorName;
        }

        public void setHandleErrorName(final String handleErrorName) {
            this.handleErrorName =handleErrorName;
        }

        public boolean isInstitutionLogin() {
            return institutionLogin;
        }

        public void setInstitutionLogin(final boolean institutionLogin) {
            this.institutionLogin = institutionLogin;
        }

        public boolean isOrcidRedirect() {
            return orcidRedirect;
        }

        public void setOrcidRedirect(final boolean orcidRedirect) {
            this.orcidRedirect = orcidRedirect;
        }

        /**
         * Check if the service URL exists.
         *
         * @return true if service url exists, false otherwise
         */
        public boolean isServiceUrl() {
            return serviceUrl != null;
        }

        /**
         * Convert the class instance to a JSON string, which will be passed to the flow context.
         *
         * @return JSON string
         */
        public String toJson() {
            final Gson gson = new Gson();
            return gson.toJson(this);
        }

        /**
         * Convert the JSON string to a class instance.
         *
         * @param jsonString a JSON string previously generated by the method .toJson()
         * @return an reconstructed instance of OpenScienceFrameworkLoginContext
         */
        public static OpenScienceFrameworkLoginContext fromJson(final String jsonString) {
            final Gson gson = new Gson();
{'fraction_non_alphanumeric': 0.06694166175604008, 'fraction_numerical': 0.002357100766057749, 'mean_word_length': 2.2802473908001546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2375892', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1989, 'n_words': 754}