Search in sources :

Example 6 with Identity

use of org.eclipse.leshan.core.request.Identity in project leshan by eclipse.

the class RegistrationUpdate method update.

/**
 * Returns an updated version of the registration.
 *
 * @param registration the registration to update
 * @return the updated registration
 */
public Registration update(Registration registration) {
    Identity identity = this.identity != null ? this.identity : registration.getIdentity();
    Link[] linkObject = this.objectLinks != null ? this.objectLinks : registration.getObjectLinks();
    long lifeTimeInSec = this.lifeTimeInSec != null ? this.lifeTimeInSec : registration.getLifeTimeInSec();
    BindingMode bindingMode = this.bindingMode != null ? this.bindingMode : registration.getBindingMode();
    String smsNumber = this.smsNumber != null ? this.smsNumber : registration.getSmsNumber();
    Map<String, String> additionalAttributes = this.additionalAttributes.isEmpty() ? registration.getAdditionalRegistrationAttributes() : updateAdditionalAttributes(registration.getAdditionalRegistrationAttributes());
    // this needs to be done in any case, even if no properties have changed, in order
    // to extend the client registration time-to-live period ...
    Date lastUpdate = new Date();
    Registration.Builder builder = new Registration.Builder(registration.getId(), registration.getEndpoint(), identity, registration.getRegistrationEndpointAddress());
    builder.lwM2mVersion(registration.getLwM2mVersion()).lifeTimeInSec(lifeTimeInSec).smsNumber(smsNumber).bindingMode(bindingMode).objectLinks(linkObject).registrationDate(registration.getRegistrationDate()).lastUpdate(lastUpdate).additionalRegistrationAttributes(additionalAttributes);
    return builder.build();
}
Also used : Identity(org.eclipse.leshan.core.request.Identity) Link(org.eclipse.leshan.Link) BindingMode(org.eclipse.leshan.core.request.BindingMode) Date(java.util.Date)

Aggregations

Identity (org.eclipse.leshan.core.request.Identity)6 Link (org.eclipse.leshan.Link)4 BindingMode (org.eclipse.leshan.core.request.BindingMode)4 HashMap (java.util.HashMap)3 EndpointContextUtil.extractIdentity (org.eclipse.leshan.core.californium.EndpointContextUtil.extractIdentity)3 JsonArray (com.eclipsesource.json.JsonArray)1 JsonObject (com.eclipsesource.json.JsonObject)1 JsonValue (com.eclipsesource.json.JsonValue)1 InetSocketAddress (java.net.InetSocketAddress)1 Date (java.util.Date)1 Request (org.eclipse.californium.core.coap.Request)1 BootstrapRequest (org.eclipse.leshan.core.request.BootstrapRequest)1 DeregisterRequest (org.eclipse.leshan.core.request.DeregisterRequest)1 RegisterRequest (org.eclipse.leshan.core.request.RegisterRequest)1 UpdateRequest (org.eclipse.leshan.core.request.UpdateRequest)1 BootstrapResponse (org.eclipse.leshan.core.response.BootstrapResponse)1 DeregisterResponse (org.eclipse.leshan.core.response.DeregisterResponse)1 RegisterResponse (org.eclipse.leshan.core.response.RegisterResponse)1 UpdateResponse (org.eclipse.leshan.core.response.UpdateResponse)1 RegistrationUpdate (org.eclipse.leshan.server.registration.RegistrationUpdate)1