cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Enable thing() and Restart thing() from Eclipse Extension

Sathishkumar_C
17-Peridot

Enable thing() and Restart thing() from Eclipse Extension

Hi All,

I want to make a thing to Enable and Restart within Eclipse Extension.

How can i do this?

 

Thing things = new Thing();

things.Enable Thing();

things.RestartThing();

 

Above code is not working.

 

Thanks & Regards,

Sathishkumar C.

1 ACCEPTED SOLUTION

Accepted Solutions

@Sathishkumar_C In that case I think the issue might be that you are attempting start / enable of thing on template level and that's not possible. You need to attempt that on the object , something like this 

 

@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = {
			"isAsync:false" })
	@ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {})
	public void CreateAThing() throws Exception {
		_logger.trace("Entering Service: CreateAThing");
		_logger.trace("Exiting Service: CreateAThing");

		EntityServices newThingService = new EntityServices();

		String name = "UniqueThingName";
		String desc = "Static Thing from Custom Extension";
		TagCollection myTag = null;

		try {
			newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew");
		} catch (Exception e) {
			System.out.println("Failed to create Thing");
			e.printStackTrace();
		}

		Thing mything = (Thing) EntityUtilities.findEntity(name, ThingworxRelationshipTypes.Thing);
		_logger.trace("Failed to find thing", mything.getName());

		try {
			mything.EnableThing();
		} catch (Exception e) {
			System.out.println("Failed to enable thing" + mything.getName());
			e.printStackTrace();
		}

View solution in original post

8 REPLIES 8

Hi @Sathishkumar_C could you share exactly what sort of error / issue you are running into?

I can't able to enable and restart the thing after creation.

Do you mean once you import the extension you can't enable and restart those Entities? could you please share any screenshot or template detail you are working with?

Thing Creation script itself written in eclipse only. After importing an extension, i will create a thing and then i will enable and restart thing.

I quickly tested it out for me it's working, not sure if you are doing something different. Here's my script from the extension in the eclipse 

 

@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = {
			"isAsync:false" })
	@ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {})
	public void CreateAThing() throws Exception {
		_logger.trace("Entering Service: CreateAThing");
		_logger.trace("Exiting Service: CreateAThing");

		EntityServices newThingService = new EntityServices();

		String name = "UniqueThingName";	
		String desc = "Static Thing from Custom Extension";
		TagCollection myTag = null;

				try {
					newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					System.out.println("Failed to create the thing");
					e.printStackTrace();
				}

		
	}

After importing the extension I get the ExtensionStandardNew ThingTemplate from which I create a thing say T2, from T2 I execute the CreateAThing

09-07-2018 14-54-07.jpg

 

Which creates a thing called "UniqueThingName" which is disabled by default, so from a different thing i check for it and enable & restart it 

 

09-07-2018 14-55-45.jpg

This is fine.

After thing created it will be disabled state. So, i want to EnableThing() and RestartThing().

newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew");
Here,
EnableThing();
RestartThing();

it should happen automatically within eclipse code.

 

Thanks & Regards,

Sathishkumar C. 

@Sathishkumar_C In that case I think the issue might be that you are attempting start / enable of thing on template level and that's not possible. You need to attempt that on the object , something like this 

 

@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = {
			"isAsync:false" })
	@ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {})
	public void CreateAThing() throws Exception {
		_logger.trace("Entering Service: CreateAThing");
		_logger.trace("Exiting Service: CreateAThing");

		EntityServices newThingService = new EntityServices();

		String name = "UniqueThingName";
		String desc = "Static Thing from Custom Extension";
		TagCollection myTag = null;

		try {
			newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew");
		} catch (Exception e) {
			System.out.println("Failed to create Thing");
			e.printStackTrace();
		}

		Thing mything = (Thing) EntityUtilities.findEntity(name, ThingworxRelationshipTypes.Thing);
		_logger.trace("Failed to find thing", mything.getName());

		try {
			mything.EnableThing();
		} catch (Exception e) {
			System.out.println("Failed to enable thing" + mything.getName());
			e.printStackTrace();
		}

Working fine.

Thanks.

Top Tags