Removing property from operation in Cumulocity does not work? - properties

I would like to remove a property from an operation in Cumulocity. I use the following code:
private final DeviceControlApi deviceControl;
OperationRepresentation operation = deviceControl.getOperation(new GId("some_op_id"));
operation.removeProperty("the_property_to_be_removed");
deviceControl.update(operation);
But after executing this piece of code the property is still there.
What is the right way to remove a property from operation?

The PUTs (updates) in Cumulocity IoT always do a merge on root level of the JSON so that you can do a partial update.
If you want to remove a property with your PUT request you need to explicitly to null.

Related

How to read values dynamically from a file for a property in updateAttribute?

I added some custom properties in the 'updateAttribute' processor using the '+' button. For example: I declared a property 'DBConnectionURL' and gave the value as 'jdbc:mysql://localhost:3306/test'. Then, in the 'DBCPConnectionPool' service controller, I simple used the value'${DBConnectionURL}' for 'Database Connection URL' property. But, I manually gave the value for 'DBConnectionURL' property.I want a way where I can feed the value dynamically from a file, so that i just need to change the value in the file and the value for 'DBConnectionURL' changes dynamically based on the value present in the file. Is there a way to do it?
Rishab,
You have to use nifi variable registry.
In conf/nifi.properties, you could configure the below configuration in it for dynamically update a value in your data flow.
nifi.variable.registry.properties=./dynamic.properties
You can give your variables in that file dynamic.properties it should present in conf directory.
For an example, If dynamic.properties files contains below values
DBCPURL= jdbc://<host>:<port>
you can use that in your data flow by using ${DBCPURL}
Note: You should restart nifi services if you change any configuration in conf/nifi.properties.Otherwise your changes not worked in dataflow.
Feel free to accept it be answer if it worked for you.

Save or Merge Patch Entity

I want following functionality in spring data rest.
If I post to a collection resource end point, server should check if the object exists. if it exists already it should perform the same functionality as it does with merge-patch on item resource. If object does not exist already it should create it.
Is this achievable in spring data rest. If so then how?
If it is possible in your use case, you might want to use PUT instead of POST, as PUT should work as you expected.
Solution with POST
You can achieve the desired behavior with Spring Data REST Event handlers.
Just create a Handler method which accepts your entity and annotate it with #HandleBeforeCreate. In this method, you can implement your behavior, i.e. check if the object exists and update it manually or just do nothing and let the Spring Data REST handle the entity creation.
#RepositoryEventHandler
public class EntityEventHandler {
#Autowired
private EntityService entityService;
#HandleBeforeCreate
public void handleEntityCreate(Entity e) {
if (entityService.exists(e)) {
entityService.update(e);
}
}
}
EDIT:
I just realized that you would also need to stop the create event after your update. You might try throwing a custom Exception and Handling it to return 200 and the updated entity.

Cumulocity using custom type properties in esper statements

I have a hard time using the properties of my custom types to write statements like contexts. For exemple, this is working:
create context TripContext
context PartionBySource
partition by source from EventCreated,
context ContextBorders
initiated by EventCreated(
type="c8y_SwitchPowerReport") as startEvent
terminated by EventCreated(
type="c8y_SwitchPowerReport") as endEvent;
However it's not enough and I need to check some of my custom properties to better define the context. I'd like to be able to do something like this:
create context TripContext
context PartionBySource
partition by
source,
getString(????, "customProp1"),
getNumber(????, "customProp2"),
...
from EventCreated,
context ContextBorders
initiated by EventCreated(
type="c8y_SwitchPowerReport",
getString(startEvent, "c8y_SwitchPower.newStatus") = "ON") as startEvent
terminated by EventCreated(
type="c8y_SwitchPowerReport",
getString(endEvent, "c8y_SwitchPower.newStatus") = "OFF") as endEvent;
I have no idea what to put instead of the ???? to make reference to the event. It's transparent for the "native" properties like source, time, type, etc. but as soon as there is a custom property, I have no idea how to access it.
As for the initiated/terminated syntax, there is something really weird I dont understand, but maybe it's more an Esper than Cumulocity problem. This is working:
terminated by EventCreated(
type="c8y_SwitchPowerReport",
getString(endEvent, "c8y_SwitchPower.newStatus") = "OFF") as endEvent
But this is not:
initiated by EventCreated(
type="c8y_SwitchPowerReport",
getString(startEvent, "c8y_SwitchPower.newStatus") = "ON") as startEvent
I got an error saying:
Failed to validate single-row function parameter expression 'startEvent': Property named 'startEvent' is not valid in any stream
Any insight would be appreciated.
I also couldn't find a quick way to get it run like you try.
But I would recommend the following approach. If you anyways relating heavily on custom fragments it makes sense to run the event through an additional stream that extracts this values:
create schema MyCustomEvent(
event Event,
myCustomString String,
myCustomNumber BigDecimal
);
insert into MyCustomEvent
select
e.event as Event,
getString(e, "myCustomString") as myCustomString,
getNumber(e, "myCustomNumber") as myCustomNumber
from EventCreated e
where getString(e, "myCustomString") is not null
and getNumber(e, "myCustomNumber") is not null;
Now you can easily create a context on MyCustomEvent instead on EventCreated.

BizTalk Receive binary file correlated on RecievedFileName

I'm having problem with routing a message of binary file to a running instance of an Orchestration using correlation of context property: ReceivedFileName. The correlation is initialized using a send with dummy file where in the Orchestration sets the ReceivedFileName context property of the message and the property gets promoted. After that routing fails of the message being received (as XmlDocument) and I can see that the ReveivedFileName context property of that message has not been promoted should it be like that? I cant figure out any way to get it promoted so I just want to make sure it should be like this.
The file names are identical but I noticed that the ReceivedFileName property of the send message doesn't have the path whereas the received message has path + file name. I have tried to add the path to the send message(sounds strange though, read it some where) but it doesn't change the outcome.
While you can set Context Proerties in an Orchestration, they are not Promoted.
You have to use the Correlation Technique described here to have the Properties Promoted when they hit the MessageBox: http://blogs.biztalk360.com/property-promotion-inside-orchestration/
Basically, you Initialize a Correlation Set based on the Properties you need Promoted.
As Ben Runchey pointed out in a comment above one have to resort to a custom pipeline and promote the FILE.ReceivedFileName there by calling:
messag.Context.Promote("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", receivedFileName);
I also removed the path from FILE.ReceivedFileName to only have the filename by calling the inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties")
and altered the value and wrote it back by calling:
inmsg.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", receivedFileName);

Ninject: More than one matching bindings are available

I have a dependency with parameters constructor. When I call the action more than 1x, it show this error:
Error activating IValidationPurchaseService
More than one matching bindings are available.
Activation path:
1) Request for IValidationPurchaseService
Suggestions:
1) Ensure that you have defined a binding for IValidationPurchaseService only once.
public ActionResult Detalhes(string regionUrl, string discountUrl, DetalhesModel detalhesModel)
{
var validationPurchaseDTO = new ValidationPurchaseDTO {...}
KernelFactory.Kernel.Bind<IValidationPurchaseService>().To<ValidationPurchaseService>()
.WithConstructorArgument("validationPurchaseDTO", validationPurchaseDTO)
.WithConstructorArgument("confirmPayment", true);
this.ValidationPurchaseService = KernelFactory.Kernel.Get<IValidationPurchaseService>();
...
}
I'm not sure what are you trying to achieve by the code you cited. The error is raised because you bind the same service more than once, so when you are trying to resolve it it can't choose one (identical) binding over another. This is not how DI Container is supposed to be operated. In your example you are not getting advantage of your DI at all. You can replace your code:
KernelFactory.Kernel.Bind<IValidationPurchaseService>().To<ValidationPurchaseService>()
.WithConstructorArgument("validationPurchaseDTO", validationPurchaseDTO)
.WithConstructorArgument("confirmPayment", true);
this.ValidationPurchaseService = KernelFactory.Kernel.Get<IValidationPurchaseService>();
With this:
this.ValidationPurchaseService = new ValidationPurchaseService(validationPurchaseDTO:validationPurchaseDTO, confirmPayment:true)
If you could explain what you are trying to achieve by using ninject in this scenario the community will be able to assist further.
Your KernelFactory probably returns the same kernel (singleton) on each successive call to the controller. Which is why you add a similar binding every time you hit the URL that activates this controller. So it probably works the first time and starts failing after the second time.