@Override
	public Response addInstance( String applicationName, String parentInstancePath, Instance instance ) {

		if( parentInstancePath == null )
			this.logger.fine( "Request: add root instance " + instance.getName() + " in " + applicationName + "." );
		else
			this.logger.fine( "Request: add instance " + instance.getName() + " under " + parentInstancePath + " in " + applicationName + "." );

		String lang = lang( this.manager );
		Response response;
		try {
			ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName );
			if( ma == null ) {
				response = handleError(
						Status.NOT_FOUND,
						new RestError( REST_INEXISTING, application( applicationName )),
						lang ).build();

			} else {
				Graphs graphs = ma.getApplication().getTemplate().getGraphs();
				String componentName = null;
				if( instance.getComponent() != null )
					componentName = instance.getComponent().getName();

				// The deserialized instance is not the real one, but just hints
				// (e.g. only the component name is pertinent, and all the exports - included overridden ones - are
				// serialized in the same map...). Now let's make this "fictional" instance real (fix it)!
				Component realComponent;
				if( componentName == null ) {
					response = handleError(
							Status.NOT_FOUND,
							new RestError( REST_MISSING_PROPERTY, value( "component" )),
							lang ).build();

				} else if((realComponent = ComponentHelpers.findComponent( graphs, componentName )) == null ) {
					response = handleError(
							Status.NOT_FOUND,
							new RestError( REST_INEXISTING, component( componentName )),
							lang ).build();

				} else {
					instance.setComponent( realComponent );
					InstanceHelpers.fixOverriddenExports( instance );

					Instance parentInstance = InstanceHelpers.findInstanceByPath( ma.getApplication(), parentInstancePath );
					this.manager.instancesMngr().addInstance( ma, parentInstance, instance );
					response = Response.ok().build();
				}
			}

		} catch( ImpossibleInsertionException | IOException e ) {
			response = RestServicesUtils.handleError(
					Status.FORBIDDEN,
					new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ),
					lang ).build();
		}

		return response;
	}
@ Override public Response addInstance ( String applicationName , String parentInstancePath , Instance instance ) { if ( parentInstancePath == null ) this . logger . fine ( "Request: add root instance " + instance . getName ( ) + " in " + applicationName + "." ) ; else this . logger . fine ( "Request: add instance " + instance . getName ( ) + " under " + parentInstancePath + " in " + applicationName + "." ) ; String lang = lang ( this . manager ) ; Response response ; try { ManagedApplication ma = this . manager . applicationMngr ( ) . findManagedApplicationByName ( applicationName ) ; if ( ma == null ) { response = handleError ( Status . NOT_FOUND , new RestError ( REST_INEXISTING , application ( applicationName ) ) , lang ) . build ( ) ; } else { Graphs graphs = ma . getApplication ( ) . getTemplate ( ) . getGraphs ( ) ; String componentName = null ; if ( instance . getComponent ( ) != null ) componentName = instance . getComponent ( ) . getName ( ) ; Component realComponent ; if ( componentName == null ) { response = handleError ( Status . NOT_FOUND , new RestError ( REST_MISSING_PROPERTY , value ( "component" ) ) , lang ) . build ( ) ; } else if ( ( realComponent = ComponentHelpers . findComponent ( graphs , componentName ) ) == null ) { response = handleError ( Status . NOT_FOUND , new RestError ( REST_INEXISTING , component ( componentName ) ) , lang ) . build ( ) ; } else { instance . setComponent ( realComponent ) ; InstanceHelpers . fixOverriddenExports ( instance ) ; Instance parentInstance = InstanceHelpers . findInstanceByPath ( ma . getApplication ( ) , parentInstancePath ) ; this . manager . instancesMngr ( ) . addInstance ( ma , parentInstance , instance ) ; response = Response . ok ( ) . build ( ) ; } } } catch ( ImpossibleInsertionException | IOException e ) { response = RestServicesUtils . handleError ( Status . FORBIDDEN , new RestError ( ErrorCode . REST_UNDETAILED_ERROR , e ) , lang ) . build ( ) ; } return response ; }
/* (non-Javadoc)
@see net.roboconf.dm.internal.rest.client.exceptions.server.IInstanceWs
#addInstance(java.lang.String, java.lang.String, net.roboconf.core.model.beans.Instance)