@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig deviceUnitConfig = entry.getMessage(); DeviceConfig deviceConfig = deviceUnitConfig.getDeviceConfig(); if (!oldInventoryStateMap.get(registry.isSandbox()).containsKey(deviceUnitConfig.getId())) { oldInventoryStateMap.get(registry.isSandbox()).put(deviceUnitConfig.getId(), deviceConfig.getInventoryState().getValue()); } if (!deviceConfig.hasInventoryState()) { throw new NotAvailableException("deviceConfig.inventoryState"); } if (!deviceConfig.getInventoryState().hasValue()) { throw new NotAvailableException("deviceConfig.inventoryState.value"); } if (deviceConfig.getInventoryState().getValue() != InventoryState.State.INSTALLED) { if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { EnablingState disabled = EnablingState.newBuilder().setValue(EnablingState.State.DISABLED).build(); throw new EntryModification(entry.setMessage(deviceUnitConfig.toBuilder().setEnablingState(disabled)), this); } } if (oldInventoryStateMap.get(registry.isSandbox()).get(deviceUnitConfig.getId()) != deviceConfig.getInventoryState().getValue()) { oldInventoryStateMap.get(registry.isSandbox()).put(deviceUnitConfig.getId(), deviceConfig.getInventoryState().getValue()); if (deviceConfig.getInventoryState().getValue() == InventoryState.State.INSTALLED) { EnablingState enabled = EnablingState.newBuilder().setValue(EnablingState.State.ENABLED).build(); throw new EntryModification(entry.setMessage(deviceUnitConfig.toBuilder().setEnablingState(enabled)), this); } } }
if (deviceUnitConfig.getDeviceConfig().getInventoryState().getValue() != InventoryState.State.INSTALLED) { continue;
if (deviceUnitConfig.getDeviceConfig().getInventoryState().getValue() != InventoryStateType.InventoryState.State.INSTALLED) { continue;
@Override public boolean verifyConfig(final UnitConfig config) throws VerificationFailedException { try { // verify device manager support. if (!DeviceManagerController.this.isSupported(config)) { return false; } // verify device state. if (config.getDeviceConfig().getInventoryState().getValue() != InventoryStateType.InventoryState.State.INSTALLED) { LOGGER.debug("Skip Device[" + config.getLabel() + "] because it is currently not installed!"); return false; } return true; } catch (CouldNotPerformException ex) { throw new VerificationFailedException("Could not verify device config!", ex); } } };
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig.Builder unitConfig = entry.getMessage().toBuilder(); DeviceConfig.Builder deviceConfig = unitConfig.getDeviceConfigBuilder(); if (!deviceConfig.hasInventoryState()) { throw new NotAvailableException("inventoryState"); } if (!unitConfig.hasPlacementConfig()) { throw new NotAvailableException("placementConfig"); } if (!unitConfig.getPlacementConfig().hasLocationId() || unitConfig.getPlacementConfig().getLocationId().isEmpty()) { throw new NotAvailableException("placementConfig.locationId"); } if (deviceConfig.getInventoryState().getValue() == InventoryState.State.INSTALLED && !deviceConfig.getInventoryState().getLocationId().equals(unitConfig.getPlacementConfig().getLocationId())) { deviceConfig.setInventoryState(deviceConfig.getInventoryStateBuilder().setLocationId(unitConfig.getPlacementConfig().getLocationId())); throw new EntryModification(entry.setMessage(unitConfig), this); } } }
/** * Method returns the state source(s) result(s) (contains state value(s)) of the input inventoryState. * * @param inventoryState The InventoryState. * @return state source(s) result(s) of the input state. */ @NotImplemented private List<RdfNodeObject> inventoryStateValue(final InventoryState inventoryState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String inventoryStateVal = inventoryState.getValue().toString(); stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(inventoryStateVal);}}, false)); // final String inventoryLocationId = "\"" + inventoryState.getLocationId() + "\"^^xsd:string"; // final String inventoryOwnerId = "\"" + inventoryState.getOwnerId() + "\"^^xsd:string"; // stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(inventoryLocationId);}}, true)); // stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(inventoryOwnerId);}}, true)); return stateSources; }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig.Builder unitConfig = entry.getMessage().toBuilder(); if (!unitConfig.hasDeviceConfig()) { throw new NotAvailableException("DeviceConfig"); } if (!unitConfig.getDeviceConfig().hasInventoryState() || !unitConfig.getDeviceConfig().getInventoryState().hasValue()) { unitConfig.getDeviceConfigBuilder().setInventoryState(DEFAULT_INVENTORY_STATE); throw new EntryModification(entry.setMessage(unitConfig), this); } } }
public static UnitConfig getDeviceConfig(String label, String serialNumber, InventoryState.State inventoryState, DeviceClass clazz, UnitConfig location) { DeviceConfig tmp = DeviceConfig.newBuilder() .setSerialNumber(serialNumber) .setDeviceClassId(clazz.getId()) .setInventoryState(InventoryStateType.InventoryState.newBuilder().setValue(inventoryState)) .build(); return UnitConfig.newBuilder() .setPlacementConfig(getDefaultPlacement(location)) .setLabel(label) .setDeviceConfig(tmp) .setType(UnitType.DEVICE) .build(); }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig.Builder unitConfig = entry.getMessage().toBuilder(); DeviceConfig.Builder deviceConfig = unitConfig.getDeviceConfigBuilder(); // verify if configured owner exists. if (deviceConfig.hasInventoryState() && deviceConfig.getInventoryState().hasOwnerId() && !deviceConfig.getInventoryState().getOwnerId().isEmpty() && !userRegistry.contains(deviceConfig.getInventoryState().getOwnerId())) { // remove unknown owner deviceConfig.setInventoryState(InventoryState.newBuilder(deviceConfig.getInventoryState()).setOwnerId("")); throw new EntryModification(entry.setMessage(unitConfig), this); } } }