Skip to content

Commit

Permalink
Allow device assignment info to be returned in device state query.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekadams committed Jul 18, 2018
1 parent 1412832 commit b066e1a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Expand Up @@ -53,6 +53,7 @@ public class DeviceStates extends RestControllerBase {
public ISearchResults<IDeviceState> searchDeviceStates(
@ApiParam(value = "Include device information", required = false) @RequestParam(defaultValue = "false") boolean includeDevice,
@ApiParam(value = "Include device type information", required = false) @RequestParam(defaultValue = "false") boolean includeDeviceType,
@ApiParam(value = "Include device assignment information", required = false) @RequestParam(defaultValue = "false") boolean includeDeviceAssignment,
@ApiParam(value = "Include customer information", required = false) @RequestParam(defaultValue = "false") boolean includeCustomer,
@ApiParam(value = "Include area information", required = false) @RequestParam(defaultValue = "false") boolean includeArea,
@ApiParam(value = "Include asset information", required = false) @RequestParam(defaultValue = "false") boolean includeAsset,
Expand All @@ -65,6 +66,7 @@ public ISearchResults<IDeviceState> searchDeviceStates(
getDeviceEventManagement());
helper.setIncludeDevice(includeDevice);
helper.setIncludeDeviceType(includeDeviceType);
helper.setIncludeDeviceAssignment(includeDeviceAssignment);
helper.setIncludeCustomer(includeCustomer);
helper.setIncludeArea(includeArea);
helper.setIncludeAsset(includeAsset);
Expand Down
Expand Up @@ -16,6 +16,7 @@
import com.sitewhere.spi.asset.IAsset;
import com.sitewhere.spi.customer.ICustomer;
import com.sitewhere.spi.device.IDevice;
import com.sitewhere.spi.device.IDeviceAssignment;
import com.sitewhere.spi.device.IDeviceType;
import com.sitewhere.spi.device.event.IDeviceAlert;
import com.sitewhere.spi.device.event.IDeviceLocation;
Expand All @@ -39,6 +40,9 @@ public class MarshaledDeviceState extends DeviceState {
/** Device type */
private IDeviceType deviceType;

/** Device assignment */
private IDeviceAssignment deviceAssignment;

/** Assigned customer */
private ICustomer customer;

Expand Down Expand Up @@ -73,6 +77,14 @@ public void setDeviceType(IDeviceType deviceType) {
this.deviceType = deviceType;
}

public IDeviceAssignment getDeviceAssignment() {
return deviceAssignment;
}

public void setDeviceAssignment(IDeviceAssignment deviceAssignment) {
this.deviceAssignment = deviceAssignment;
}

public ICustomer getCustomer() {
return customer;
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.sitewhere.spi.asset.IAssetManagement;
import com.sitewhere.spi.customer.ICustomer;
import com.sitewhere.spi.device.IDevice;
import com.sitewhere.spi.device.IDeviceAssignment;
import com.sitewhere.spi.device.IDeviceManagement;
import com.sitewhere.spi.device.IDeviceType;
import com.sitewhere.spi.device.event.IDeviceAlert;
Expand All @@ -44,6 +45,9 @@ public class DeviceStateMarshalHelper {
/** Indicates whether to include device type */
private boolean includeDeviceType = false;

/** Indicates whether to include device assignment information */
private boolean includeDeviceAssignment = false;

/** Indicates whether to include customer information */
private boolean includeCustomer = false;

Expand Down Expand Up @@ -118,6 +122,15 @@ protected void addAssignmentDetail(IDeviceState source, IAssetManagement assetMa
}
}

// Add device assignment information.
if (isIncludeDeviceAssignment()) {
IDeviceAssignment deviceAssignment = getDeviceManagement()
.getDeviceAssignment(source.getDeviceAssignmentId());
if (deviceAssignment != null) {
result.setDeviceAssignment(deviceAssignment);
}
}

// If customer is assigned, look it up.
if ((isIncludeCustomer()) && (source.getCustomerId() != null)) {
ICustomer customer = getDeviceManagement().getCustomer(source.getCustomerId());
Expand Down Expand Up @@ -222,6 +235,14 @@ public void setIncludeDeviceType(boolean includeDeviceType) {
this.includeDeviceType = includeDeviceType;
}

public boolean isIncludeDeviceAssignment() {
return includeDeviceAssignment;
}

public void setIncludeDeviceAssignment(boolean includeDeviceAssignment) {
this.includeDeviceAssignment = includeDeviceAssignment;
}

public boolean isIncludeCustomer() {
return includeCustomer;
}
Expand Down

0 comments on commit b066e1a

Please sign in to comment.