agave-systems/systems-core/src/main/java/org/iplantc/service/systems/manager/SystemManager.java
/**
	 * Creates a new RemoteSystem object from the json object. If the passed in system is 
	 * not null, it is updated with the values from the json object and id is preserved.
	 * @param json
	 * @param apiUsername
	 * @param system
	 * @return RemoteSystem
	 * @throws SystemException
	 * @throws PermissionException 
	 */
Creates a new RemoteSystem object from the json object. If the passed in system is
not null, it is updated with the values from the json object and id is preserved.
Creates a new RemoteSystem object from the json object . If the passed in system is not null it is updated with the values from the json object and id is preserved .
public RemoteSystem parseSystem(JSONObject json, String apiUsername, RemoteSystem system) 
	throws SystemException, PermissionException
	{
		if (StringUtils.isEmpty(apiUsername)) {
			throw new SystemException("No username provided.");
		}
		if (system != null && system.getUserRole(apiUsername).getRole().equals(RoleType.NONE)) {
			throw new PermissionException("System " + system.getSystemId() + 
					" already exists and you do not have the necessary role to update it.");
		}
		if (json == null) 
		{
			throw new SystemException("No system description provided");
		} 
		else if (json.has("type")) {
			try 
			{
				RemoteSystemType type = RemoteSystemType.valueOf(json.getString("type").toUpperCase());
				if (type.equals(RemoteSystemType.EXECUTION)) 
				{
					if (system == null) 
					{
						system = new ExecutionSystem();
						system.setOwner(apiUsername);
						system.setUuid(new AgaveUUID(UUIDType.SYSTEM).toString());
					} else if (!(system instanceof ExecutionSystem)) {
						throw new SystemException("System " + system.getSystemId() + 
								" already exists as a storage system. Once declared, "
								+ "systems cannot be redefined as a different type.");
					} 
					system = ExecutionSystem.fromJSON(json, (ExecutionSystem)system);
				}
				else if (type.equals(RemoteSystemType.STORAGE)) 
				{
					if (system == null) 
					{
						system = new StorageSystem();
						system.setOwner(apiUsername);
						system.setUuid(new AgaveUUID(UUIDType.SYSTEM).toString());
					} 
					else if (!(system instanceof StorageSystem)) 
					{
						throw new SystemException("System " + system.getSystemId() + 
								" already exists as an execution system. Once declared, "
								+ "systems cannot be redefined as a different type.");
					}
					system = StorageSystem.fromJSON(json, (StorageSystem)system);
				} 
				else 
				{
					throw new SystemException("Invalid 'type' value. " +
							"Please specify one of: " + ServiceUtils.explode(",",Arrays.asList(RemoteSystemType.values())));
				}
				system.setLastUpdated(new Date());
				return system;
			} 
			catch (SystemException e) {
				throw e;
			} 
			catch (Exception e) {
				throw new SystemException("Invalid 'type' value. " +
						"Please specify one of: " + ServiceUtils.explode(",",Arrays.asList(RemoteSystemType.values())));
			}
		} else {
			throw new SystemException("No 'type' value specified. " +
					"Please specify one of: " + ServiceUtils.explode(",",Arrays.asList(RemoteSystemType.values())));
		}
	}
public RemoteSystem parseSystem ( JSONObject json , String apiUsername , RemoteSystem system ) throws SystemException , PermissionException { if ( StringUtils . isEmpty ( apiUsername ) ) { throw new SystemException ( "No username provided." ) ; } if ( system != null && system . getUserRole ( apiUsername ) . getRole ( ) . equals ( RoleType . NONE ) ) { throw new PermissionException ( "System " + system . getSystemId ( ) + " already exists and you do not have the necessary role to update it." ) ; } if ( json == null ) { throw new SystemException ( "No system description provided" ) ; } else if ( json . has ( "type" ) ) { try { RemoteSystemType type = RemoteSystemType . valueOf ( json . getString ( "type" ) . toUpperCase ( ) ) ; if ( type . equals ( RemoteSystemType . EXECUTION ) ) { if ( system == null ) { system = new ExecutionSystem ( ) ; system . setOwner ( apiUsername ) ; system . setUuid ( new AgaveUUID ( UUIDType . SYSTEM ) . toString ( ) ) ; } else if ( ! ( system instanceof ExecutionSystem ) ) { throw new SystemException ( "System " + system . getSystemId ( ) + " already exists as a storage system. Once declared, " + "systems cannot be redefined as a different type." ) ; } system = ExecutionSystem . fromJSON ( json , ( ExecutionSystem ) system ) ; } else if ( type . equals ( RemoteSystemType . STORAGE ) ) { if ( system == null ) { system = new StorageSystem ( ) ; system . setOwner ( apiUsername ) ; system . setUuid ( new AgaveUUID ( UUIDType . SYSTEM ) . toString ( ) ) ; } else if ( ! ( system instanceof StorageSystem ) ) { throw new SystemException ( "System " + system . getSystemId ( ) + " already exists as an execution system. Once declared, " + "systems cannot be redefined as a different type." ) ; } system = StorageSystem . fromJSON ( json , ( StorageSystem ) system ) ; } else { throw new SystemException ( "Invalid 'type' value. " + "Please specify one of: " + ServiceUtils . explode ( "," , Arrays . asList ( RemoteSystemType . values ( ) ) ) ) ; } system . setLastUpdated ( new Date ( ) ) ; return system ; } catch ( SystemException e ) { throw e ; } catch ( Exception e ) { throw new SystemException ( "Invalid 'type' value. " + "Please specify one of: " + ServiceUtils . explode ( "," , Arrays . asList ( RemoteSystemType . values ( ) ) ) ) ; } } else { throw new SystemException ( "No 'type' value specified. " + "Please specify one of: " + ServiceUtils . explode ( "," , Arrays . asList ( RemoteSystemType . values ( ) ) ) ) ; } }
Creates a new RemoteSystem object from the json object.
Creates a new RemoteSystem object from the json object .
//				system.setOwner(owner);