@Override
	public void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName )
	throws IOException, UnauthorizedActionException {

		boolean valid = false;
		if( instancePathOrComponentName == null ) {
			valid = true;

		} else if( instancePathOrComponentName.startsWith( "@" )) {
			Component comp = ComponentHelpers.findComponent( app, instancePathOrComponentName.substring( 1 ));
			valid = comp != null;

		} else {
			Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName );
			valid = instance != null;
			if( instance != null ) {
				if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED )
					throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." );

				if( ! InstanceHelpers.isTarget( instance ))
					throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName );
			}
		}

		if( valid )
			saveAssociation( app, targetId, instancePathOrComponentName, true );
	}
@ Override public void associateTargetWith ( String targetId , AbstractApplication app , String instancePathOrComponentName ) throws IOException , UnauthorizedActionException { boolean valid = false ; if ( instancePathOrComponentName == null ) { valid = true ; } else if ( instancePathOrComponentName . startsWith ( "@" ) ) { Component comp = ComponentHelpers . findComponent ( app , instancePathOrComponentName . substring ( 1 ) ) ; valid = comp != null ; } else { Instance instance = InstanceHelpers . findInstanceByPath ( app , instancePathOrComponentName ) ; valid = instance != null ; if ( instance != null ) { if ( instance . getStatus ( ) != InstanceStatus . NOT_DEPLOYED ) throw new UnauthorizedActionException ( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ) ; if ( ! InstanceHelpers . isTarget ( instance ) ) throw new IllegalArgumentException ( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ) ; } } if ( valid ) saveAssociation ( app , targetId , instancePathOrComponentName , true ) ; }
Associating targets and application instances / components