agave-systems/systems-core/src/main/java/org/iplantc/service/systems/model/StorageSystem.java
/**
	 * Updates the given StorageSystem with the json representation provided
	 * @param jsonSystem the json representation of the system
	 * @param system the original storage system to update
	 * @return a new StorageSystem
	 * @throws SystemException if the JSONObject is an invalid representation of the system
	 */
Updates the given StorageSystem with the json representation provided
@param jsonSystem the json representation of the system
@param system the original storage system to update
@return a new StorageSystem
@throws SystemException if the JSONObject is an invalid representation of the system
Updates the given StorageSystem with the json representation provided @param jsonSystem the json representation of the system @param system the original storage system to update @return a new StorageSystem @throws SystemException if the JSONObject is an invalid representation of the system
public static StorageSystem fromJSON(JSONObject jsonSystem, StorageSystem system) throws SystemException
	{
		if (system == null) {
			system = new StorageSystem();
			system.setUuid(new AgaveUUID(UUIDType.SYSTEM).toString());
		}
		try {
			if (ServiceUtils.isNonEmptyString(jsonSystem, "id")) {
				system.setSystemId(jsonSystem.getString("id"));
			} else {
				throw new SystemArgumentException("Please specify a valid string value for the 'id' field.");
			}
			if (ServiceUtils.isNonEmptyString(jsonSystem, "name")) {
				system.setName(jsonSystem.getString("name"));
			} else {
				throw new SystemArgumentException("Please specify a valid string value for the 'name' field.");
			}
			if (ServiceUtils.isValidString(jsonSystem, "status"))
			{
				try {
					SystemStatusType statusType = SystemStatusType.valueOf(jsonSystem.getString("status").toUpperCase());
					system.setStatus(statusType);
				} catch (Exception e) {
					throw new SystemArgumentException("Invalid 'status' value. " +
							"Please specify one of: '" + ServiceUtils.explode(", '", Arrays.asList(SystemStatusType.values())) + "'");
				}
			}
			else
			{
				system.setStatus(SystemStatusType.UP);
			}
			if (ServiceUtils.isNonEmptyString(jsonSystem, "type"))
			{
				try {
					RemoteSystemType systemType = RemoteSystemType.valueOf(jsonSystem.getString("type").toUpperCase());
					system.setType(systemType);
				} catch (Exception e) {
					throw new SystemArgumentException("Invalid 'type' value. " +
							"Please specify one of: '" + ServiceUtils.explode(", '", Arrays.asList(RemoteSystemType.values())) + "'");
				}
			} 
			else
			{
				throw new SystemArgumentException("No 'type' value specified. " +
						"Please specify one of: '" + ServiceUtils.explode(", '", Arrays.asList(RemoteSystemType.values())) + "'");
			}
			if (ServiceUtils.isValidString(jsonSystem, "description")) {
				system.setDescription(jsonSystem.getString("description"));
			} 
			else
			{
				system.setDescription(null);
			}
			if (jsonSystem.has("site")) 
			{
				if (ServiceUtils.isNonEmptyString(jsonSystem, "site")) {
					system.setSite(jsonSystem.getString("site"));
				} else {
					throw new SystemArgumentException("Invalid 'site' value. " +
							"If specified, please specify a valid name for the site where this system lives");
				}
			}
			else
			{
				system.setSite(null);
			}
			if (jsonSystem.has("available")) 
			{
				try
				{
					boolean isAvailable = jsonSystem.getBoolean("available");
					system.setAvailable(isAvailable);
				} catch (Exception e) {
					throw new SystemArgumentException("Invalid 'available' value. If provided, " +
							"please specify either true or false depending on whether you would " +
							"like this system to be available for use. Default: true");
				}
			} 
			else {
				system.setAvailable(true);
			}
			if (jsonSystem.has("storage"))
			{
				JSONObject jsonStorage = jsonSystem.getJSONObject("storage");
				if (jsonStorage == null) {
					throw new SystemArgumentException("Invalid 'storage' value. Please specify a " +
							"JSON object representing a valid 'storage' configuration.");
				} 
				else
				{
					if (system.getStorageConfig() != null) {
						for (AuthConfig authConfig: system.getStorageConfig().getAuthConfigs()) 
						{
							String salt = system.getEncryptionKeyForAuthConfig(authConfig);
							if (!StringUtils.isEmpty(authConfig.getPassword())) {
								authConfig.setPassword(authConfig.getClearTextPassword(salt));
							}
							if (!StringUtils.isEmpty(authConfig.getCredential())) {
								authConfig.setCredential(authConfig.getClearTextCredential(salt));
							}
							if (!StringUtils.isEmpty(authConfig.getPublicKey())) {
								authConfig.setPublicKey(authConfig.getClearTextPublicKey(salt));
							}
							if (!StringUtils.isEmpty(authConfig.getPrivateKey())) {
								authConfig.setPrivateKey(authConfig.getClearTextPrivateKey(salt));
							}
						}
					}
					StorageConfig storageConfig = StorageConfig.fromJSON(jsonStorage, system.getStorageConfig());
					for (AuthConfig authConfig: storageConfig.getAuthConfigs()) 
					{
						String salt = system.getEncryptionKeyForAuthConfig(authConfig);
						if (!StringUtils.isEmpty(authConfig.getPassword())) {
							authConfig.encryptCurrentPassword(salt);
						}
						if (!StringUtils.isEmpty(authConfig.getCredential())) {
							authConfig.encryptCurrentCredential(salt);
						}
						if (!StringUtils.isEmpty(authConfig.getPublicKey())) {
							authConfig.encryptCurrentPublicKey(salt);
						}
						if (!StringUtils.isEmpty(authConfig.getPrivateKey())) {
							authConfig.encryptCurrentPrivateKey(salt);
						}
					}
					system.setStorageConfig(storageConfig);
				}
			} 
			else { 
				throw new SystemArgumentException("No 'storage' value specified. Please specify a " +
							"JSON object representing a valid 'storage' configuration.");
			}
 {
 catch (JSONException e) {
else {
throw new SystemArgumentException("No 'protocol' value specified. " +
		"Please specify one of: '" + ServiceUtils.explode(", '", Arrays.asList(StorageProtocolType.values())) + "'");
		}
		catch (JSONException e) {
            throw new SystemException("Failed to parse storage system.", e);
		}
		catch (SystemArgumentException e) {
            throw new SystemException(e.getMessage(), e);
		}
		catch (Exception e) {
            throw new SystemException("Failed to parse storage system: " + e.getMessage(), e);
		}
		return system;
	}
public static StorageSystem fromJSON ( JSONObject jsonSystem , StorageSystem system ) throws SystemException { if ( system == null ) { system = new StorageSystem ( ) ; system . setUuid ( new AgaveUUID ( UUIDType . SYSTEM ) . toString ( ) ) ; } try { if ( ServiceUtils . isNonEmptyString ( jsonSystem , "id" ) ) { system . setSystemId ( jsonSystem . getString ( "id" ) ) ; } else { throw new SystemArgumentException ( "Please specify a valid string value for the 'id' field." ) ; } if ( ServiceUtils . isNonEmptyString ( jsonSystem , "name" ) ) { system . setName ( jsonSystem . getString ( "name" ) ) ; } else { throw new SystemArgumentException ( "Please specify a valid string value for the 'name' field." ) ; } if ( ServiceUtils . isValidString ( jsonSystem , "status" ) ) { try { SystemStatusType statusType = SystemStatusType . valueOf ( jsonSystem . getString ( "status" ) . toUpperCase ( ) ) ; system . setStatus ( statusType ) ; } catch ( Exception e ) { throw new SystemArgumentException ( "Invalid 'status' value. " + "Please specify one of: '" + ServiceUtils . explode ( ", '" , Arrays . asList ( SystemStatusType . values ( ) ) ) + "'" ) ; } } else { system . setStatus ( SystemStatusType . UP ) ; } if ( ServiceUtils . isNonEmptyString ( jsonSystem , "type" ) ) { try { RemoteSystemType systemType = RemoteSystemType . valueOf ( jsonSystem . getString ( "type" ) . toUpperCase ( ) ) ; system . setType ( systemType ) ; } catch ( Exception e ) { throw new SystemArgumentException ( "Invalid 'type' value. " + "Please specify one of: '" + ServiceUtils . explode ( ", '" , Arrays . asList ( RemoteSystemType . values ( ) ) ) + "'" ) ; } } else { throw new SystemArgumentException ( "No 'type' value specified. " + "Please specify one of: '" + ServiceUtils . explode ( ", '" , Arrays . asList ( RemoteSystemType . values ( ) ) ) + "'" ) ; } if ( ServiceUtils . isValidString ( jsonSystem , "description" ) ) { system . setDescription ( jsonSystem . getString ( "description" ) ) ; } else { system . setDescription ( null ) ; } if ( jsonSystem . has ( "site" ) ) { if ( ServiceUtils . isNonEmptyString ( jsonSystem , "site" ) ) { system . setSite ( jsonSystem . getString ( "site" ) ) ; } else { throw new SystemArgumentException ( "Invalid 'site' value. " + "If specified, please specify a valid name for the site where this system lives" ) ; } } else { system . setSite ( null ) ; } if ( jsonSystem . has ( "available" ) ) { try { boolean isAvailable = jsonSystem . getBoolean ( "available" ) ; system . setAvailable ( isAvailable ) ; } catch ( Exception e ) { throw new SystemArgumentException ( "Invalid 'available' value. If provided, " + "please specify either true or false depending on whether you would " + "like this system to be available for use. Default: true" ) ; } } else { system . setAvailable ( true ) ; } if ( jsonSystem . has ( "storage" ) ) { JSONObject jsonStorage = jsonSystem . getJSONObject ( "storage" ) ; if ( jsonStorage == null ) { throw new SystemArgumentException ( "Invalid 'storage' value. Please specify a " + "JSON object representing a valid 'storage' configuration." ) ; } else { if ( system . getStorageConfig ( ) != null ) { for ( AuthConfig authConfig : system . getStorageConfig ( ) . getAuthConfigs ( ) ) { String salt = system . getEncryptionKeyForAuthConfig ( authConfig ) ; if ( ! StringUtils . isEmpty ( authConfig . getPassword ( ) ) ) { authConfig . setPassword ( authConfig . getClearTextPassword ( salt ) ) ; } if ( ! StringUtils . isEmpty ( authConfig . getCredential ( ) ) ) { authConfig . setCredential ( authConfig . getClearTextCredential ( salt ) ) ; } if ( ! StringUtils . isEmpty ( authConfig . getPublicKey ( ) ) ) { authConfig . setPublicKey ( authConfig . getClearTextPublicKey ( salt ) ) ; } if ( ! StringUtils . isEmpty ( authConfig . getPrivateKey ( ) ) ) { authConfig . setPrivateKey ( authConfig . getClearTextPrivateKey ( salt ) ) ; } } } StorageConfig storageConfig = StorageConfig . fromJSON ( jsonStorage , system . getStorageConfig ( ) ) ; for ( AuthConfig authConfig : storageConfig . getAuthConfigs ( ) ) { String salt = system . getEncryptionKeyForAuthConfig ( authConfig ) ; if ( ! StringUtils . isEmpty ( authConfig . getPassword ( ) ) ) { authConfig . encryptCurrentPassword ( salt ) ; } if ( ! StringUtils . isEmpty ( authConfig . getCredential ( ) ) ) { authConfig . encryptCurrentCredential ( salt ) ; } if ( ! StringUtils . isEmpty ( authConfig . getPublicKey ( ) ) ) { authConfig . encryptCurrentPublicKey ( salt ) ; } if ( ! StringUtils . isEmpty ( authConfig . getPrivateKey ( ) ) ) { authConfig . encryptCurrentPrivateKey ( salt ) ; } } system . setStorageConfig ( storageConfig ) ; } } else { throw new SystemArgumentException ( "No 'storage' value specified. Please specify a " + "JSON object representing a valid 'storage' configuration." ) ; } } catch ( JSONException e ) { throw new SystemException ( "Failed to parse storage system." , e ) ; } catch ( SystemArgumentException e ) { throw new SystemException ( e . getMessage ( ) , e ) ; } catch ( Exception e ) { throw new SystemException ( "Failed to parse storage system: " + e . getMessage ( ) , e ) ; } return system ; }
Updates the given StorageSystem with the json representation provided
 @param jsonSystem the json representation of the system
 @param system the original storage system to update
 @return a new StorageSystem
 @throws SystemException if the JSONObject is an invalid representation of the system
Updates the given StorageSystem with the json representation provided @param jsonSystem the json representation of the system @param system the original storage system to update @return a new StorageSystem @throws SystemException if the JSONObject is an invalid representation of the system
//			if (jsonSystem.has("default") && !jsonSystem.isNull("default"))  //			{ //				try //				{ //					boolean isDefaultSystem = jsonSystem.getBoolean("default"); //					system.setGlobalDefault(isDefaultSystem); //				} catch (Exception e) { //					throw new SystemArgumentException("Invalid 'default' value. If provided, " + //							"please specify either true or false depending on whether you would " + //							"like to use this as your default execution system. Default: false"); //				} //			}  // if the system already exists, the current passwords and credentials are all encrypted // using information from the current system. After updating the storage config, we will // not be able to decrypt the encrypted fields with the new system information, so // we must first decrypt all the passwords, then we can go back and encrypt them again // after updating the storage config // we encrypt the password after parsing the object. Technically he password // needs to be updated every time the loginConfig's hostname changes. // In practice we need to updated it on every update, so we do that here. //			if (jsonSystem.has("protocol") && !StringUtils.isEmpty(jsonSystem.getString("protocol"))) { //				try { //					StorageProtocolType protocolType = StorageProtocolType.valueOf(jsonSystem.getString("protocol").toUpperCase()); //					system.setProtocol(protocolType); //				} catch (JSONException e) { //					throw new SystemArgumentException("Invalid 'protocol' value. Please specify one of: '" + ServiceUtils.explode(", '", Arrays.asList(StorageProtocolType.values())) + "'"); //				} //				 //			} else { //				throw new SystemArgumentException("No 'protocol' value specified. " + //						"Please specify one of: '" + ServiceUtils.explode(", '", Arrays.asList(StorageProtocolType.values())) + "'"); //			}