agave-systems/systems-core/src/main/java/org/iplantc/service/systems/model/CredentialServer.java
/**
	 * Deserializes a json object into a CredentialServer. If the provided CredentialServer is
	 * not null, it is updated with the values from the json object. The resulting object is
	 * validated before sending back.
	 * 
	 * @param jsonSystem
	 * @param credentialServer
	 * @return
	 * @throws SystemException
	 */
Deserializes a json object into a CredentialServer. If the provided CredentialServer is
not null, it is updated with the values from the json object. The resulting object is
validated before sending back.

@param jsonSystem
@param credentialServer
@return
@throws SystemException
Deserializes a json object into a CredentialServer . If the provided CredentialServer is not null it is updated with the values from the json object . The resulting object is validated before sending back . @param jsonSystem @param credentialServer @return @throws SystemException
public static CredentialServer fromJSON(JSONObject jsonSystem, CredentialServer credentialServer) throws SystemException
	{
		if (credentialServer == null) {
			credentialServer = new CredentialServer();
		}
		try {
			if (ServiceUtils.isNonEmptyString(jsonSystem, "name")) {
				credentialServer.setName(jsonSystem.getString("name"));
			} else {
				throw new SystemArgumentException("Please specify a valid string value for the 'auth.server.name' field.");
			}
			if (ServiceUtils.isNonEmptyString(jsonSystem, "endpoint")) {
				credentialServer.setEndpoint(jsonSystem.getString("endpoint"));
			} else {
				throw new SystemArgumentException("Please specify a valid string value for the 'auth.server.endpoint' field.");
			}
			if (jsonSystem.has("port") && !jsonSystem.isNull("port"))
			{
				try 
				{
					int portNumber = jsonSystem.getInt("port");
					if (portNumber > 0) {
						credentialServer.setPort(portNumber);
					} else {
						throw new SystemArgumentException("Invalid 'auth.server.port' value. " +
								"If provided, please specify a positive integer value for the port number.");
					}
				}
				catch (Exception e) {
					throw new SystemArgumentException("Invalid 'auth.server.port' value " + jsonSystem.get("port") + ". " +
							"If provided, please specify a positive integer value for the port number.");
				}
			}
			else
			{
				credentialServer.setPort(-1);
			}
			if (jsonSystem.has("protocol") && !StringUtils.isEmpty(jsonSystem.getString("protocol"))) {
				try {
					CredentialServerProtocolType protocolType = CredentialServerProtocolType.valueOf(jsonSystem.getString("protocol").toUpperCase());
					credentialServer.setProtocol(protocolType);
				} catch (Exception e) {
					throw new SystemArgumentException("Invalid 'auth.server.protocol' value " + 
							jsonSystem.getString("protocol") + ". Please specify one of: " +
							"'" + ServiceUtils.explode("', '", Arrays.asList(CredentialServerProtocolType.values())) + "'");
				}
			} else {
				throw new SystemArgumentException("No 'auth.server.protocol' value specified. " +
						"Please specify one of: '" + ServiceUtils.explode("', '", Arrays.asList(CredentialServerProtocolType.values())) + "'");
			}
		}
		catch (JSONException e) {
			throw new SystemException("Failed to parse ExecutionSystem.", e);
		}
		catch (SystemArgumentException e) {
			throw new SystemException("Failed to parse ExecutionSystem. " + e.getMessage(), e);
		}
		catch (Exception e) {
			throw new SystemException("Failed to parse ExecutionSystem: " + e.getMessage(), e);
		}
		return credentialServer;
	}
public static CredentialServer fromJSON ( JSONObject jsonSystem , CredentialServer credentialServer ) throws SystemException { if ( credentialServer == null ) { credentialServer = new CredentialServer ( ) ; } try { if ( ServiceUtils . isNonEmptyString ( jsonSystem , "name" ) ) { credentialServer . setName ( jsonSystem . getString ( "name" ) ) ; } else { throw new SystemArgumentException ( "Please specify a valid string value for the 'auth.server.name' field." ) ; } if ( ServiceUtils . isNonEmptyString ( jsonSystem , "endpoint" ) ) { credentialServer . setEndpoint ( jsonSystem . getString ( "endpoint" ) ) ; } else { throw new SystemArgumentException ( "Please specify a valid string value for the 'auth.server.endpoint' field." ) ; } if ( jsonSystem . has ( "port" ) && ! jsonSystem . isNull ( "port" ) ) { try { int portNumber = jsonSystem . getInt ( "port" ) ; if ( portNumber > 0 ) { credentialServer . setPort ( portNumber ) ; } else { throw new SystemArgumentException ( "Invalid 'auth.server.port' value. " + "If provided, please specify a positive integer value for the port number." ) ; } } catch ( Exception e ) { throw new SystemArgumentException ( "Invalid 'auth.server.port' value " + jsonSystem . get ( "port" ) + ". " + "If provided, please specify a positive integer value for the port number." ) ; } } else { credentialServer . setPort ( - 1 ) ; } if ( jsonSystem . has ( "protocol" ) && ! StringUtils . isEmpty ( jsonSystem . getString ( "protocol" ) ) ) { try { CredentialServerProtocolType protocolType = CredentialServerProtocolType . valueOf ( jsonSystem . getString ( "protocol" ) . toUpperCase ( ) ) ; credentialServer . setProtocol ( protocolType ) ; } catch ( Exception e ) { throw new SystemArgumentException ( "Invalid 'auth.server.protocol' value " + jsonSystem . getString ( "protocol" ) + ". Please specify one of: " + "'" + ServiceUtils . explode ( "', '" , Arrays . asList ( CredentialServerProtocolType . values ( ) ) ) + "'" ) ; } } else { throw new SystemArgumentException ( "No 'auth.server.protocol' value specified. " + "Please specify one of: '" + ServiceUtils . explode ( "', '" , Arrays . asList ( CredentialServerProtocolType . values ( ) ) ) + "'" ) ; } } catch ( JSONException e ) { throw new SystemException ( "Failed to parse ExecutionSystem." , e ) ; } catch ( SystemArgumentException e ) { throw new SystemException ( "Failed to parse ExecutionSystem. " + e . getMessage ( ) , e ) ; } catch ( Exception e ) { throw new SystemException ( "Failed to parse ExecutionSystem: " + e . getMessage ( ) , e ) ; } return credentialServer ; }
Deserializes a json object into a CredentialServer.
Deserializes a json object into a CredentialServer .