Class ApiSerializer


  • public final class ApiSerializer
    extends Object
    • Method Detail

      • getTokenOrEmpty

        public Optional<String> getTokenOrEmpty​(org.json.JSONObject jsonObject)
        if jsonObject contains "IsSuccess" with value of true then value of "Token" if non-empty is returned within an Optional; otherwise Optional.empty()
        Parameters:
        jsonObject - JSON object containing "IsSuccess" and "Token"
        Returns:
        Optional containing "Token" if "IsSuccess" has value of true and Token is not empty; otherwise Optional.empty()
      • getIsSuccess

        public boolean getIsSuccess​(org.json.JSONObject jsonObject)
        returns the value of "IsSuccess" from the provided jsonObject if non-null; otherwise, false
        Parameters:
        jsonObject - JSON object containing the "IsSuccess" value to extract
        Returns:
        value of "IsSuccess" from the provided jsonObject if non-null; otherwise, false
      • getScanResult

        public ScanResult getScanResult​(org.json.JSONObject jsonObject)
      • getResultIsSuccess

        public boolean getResultIsSuccess​(org.json.JSONObject jsonObject)
        returns the value of "IsSuccess" and "Result" from the provided jsonObject if non-null; otherwise, false
        Parameters:
        jsonObject - JSON object containing the "IsSuccess" value to extract
        Returns:
        value of "IsSuccess" from the provided jsonObject if non-null; otherwise, false
      • getStatus

        public Optional<String> getStatus​(org.json.JSONObject jsonObject)
        returns the value of "Status" from the provided jsonObject if non-null and Status is not empty; otherwise
        Parameters:
        jsonObject - JSON object containing "Status" key
        Returns:
        Optional containing value of "Status" from jsonObject if not empty on success; otherwise, Optional.empty()
      • getConfigNames

        public Optional<List<String>> getConfigNames​(org.json.JSONArray configs)
        returns List{String} of all scan config names found in configs
        Parameters:
        configs - JSONArray of scan config JSONObjects containing "Name" key
        Returns:
        Optional containing List{String} which in turn contains all "Name" keys found in configs - if configs is non-null; Otherwise, Optional.empty()
      • getScanConfigXml

        public String getScanConfigXml​(freemarker.template.Template template,
                                       String name,
                                       URL targetURL)
                                throws IOException,
                                       freemarker.template.TemplateException
        constructs scan config XML document using template with provided name and target
        Parameters:
        template - template used to produce XML
        name - name of the new scan config
        targetURL - target of the scan config
        Returns:
        String representing scan config in XML format
        Throws:
        IOException - thrown if I/O error occurs during template processing
        freemarker.template.TemplateException - if a problem occurs during template processing
        IllegalArgumentException - if any of the provided arguments are null, or in the case of Strings empty
        MalformedURLException - if target is not a va
      • getScanConfigId

        public Optional<String> getScanConfigId​(org.json.JSONObject config)
      • findByConfigName

        public Optional<org.json.JSONObject> findByConfigName​(org.json.JSONArray configs,
                                                              String configName)
        returns the JSONObject for the item in configs with "Name" matching name if found; otherwise Optional.empty()
        Parameters:
        configs - JSONArray to search through
        configName - name of config to find
        Returns:
        Optional containing the matching JSONObject on success; otherwise Optional.empty()
      • getBooleansFrom

        public Optional<Boolean> getBooleansFrom​(org.json.JSONObject jsonObject,
                                                 String... keys)
        returns true if all given keys in jsonObject are true
        Parameters:
        jsonObject - json object containing keys
        keys - keys for the boolean fields of jsonObject
        Returns:
        true if all keys are present and true
      • getClientIdNamePairs

        public Optional<List<ClientIdNamePair>> getClientIdNamePairs​(org.json.JSONArray clients)
        returns a list of ClientIdNamePair objects extracted from given JSONArray
        Parameters:
        clients - JSONArray containing items with format { ClientId = String, ClientName = String }
        Returns:
        on success list of ClientIdNamePairs extracted from clients; otherwise, Optional.empty()