@Override public URI getAreaIdentifier(IArea area) throws SiteWhereException { return createUri(SITEWHERE_PROTOCOL + "area/" + area.getToken()); }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IArea source, Document target) { target.append(PROP_AREA_TYPE_ID, source.getAreaTypeId()); target.append(PROP_PARENT_AREA_ID, source.getParentAreaId()); target.append(PROP_NAME, source.getName()); target.append(PROP_DESCRIPTION, source.getDescription()); MongoBoundedEntity.saveBounds(source, target); MongoBrandedEntity.toDocument(source, target); }
@Override public List<IArea> getAreaChildren(String token) throws SiteWhereException { IArea existing = getAreaByToken(token); if (existing == null) { throw new SiteWhereSystemException(ErrorCode.InvalidAreaToken, ErrorLevel.ERROR); } MongoCollection<Document> areas = getMongoClient().getAreasCollection(); Document query = new Document(MongoArea.PROP_PARENT_AREA_ID, existing.getId()); Document sort = new Document(MongoArea.PROP_NAME, 1); SearchResults<IArea> matches = MongoPersistence.search(IArea.class, areas, query, sort, SearchCriteria.ALL, LOOKUP); return matches.getResults(); }
/** * Convert area from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GArea asGrpcArea(IArea api) throws SiteWhereException { GArea.Builder grpc = GArea.newBuilder(); grpc.setAreaTypeId(CommonModelConverter.asGrpcUuid(api.getAreaTypeId())); if (api.getParentAreaId() != null) { grpc.setParentAreaId(CommonModelConverter.asGrpcUuid(api.getParentAreaId())); } grpc.setName(api.getName()); grpc.setDescription(api.getDescription()); grpc.addAllBounds(CommonModelConverter.asGrpcLocations(api.getBounds())); grpc.setEntityInformation(CommonModelConverter.asGrpcEntityInformation(api)); grpc.setBranding(CommonModelConverter.asGrpcBrandingInformation(api)); return grpc.build(); }
public Builder(String token, String name, IArea area) { request.setToken(token); request.setName(name); request.setAreaToken(area.getToken()); }
/** * Common logic for creating a device assignment from a request. * * @param request * @param customer * @param area * @param asset * @param device * @return * @throws SiteWhereException */ public static DeviceAssignment deviceAssignmentCreateLogic(IDeviceAssignmentCreateRequest request, ICustomer customer, IArea area, IAsset asset, IDevice device) throws SiteWhereException { DeviceAssignment assignment = new DeviceAssignment(); Persistence.entityCreateLogic(request, assignment); assignment.setCustomerId(customer != null ? customer.getId() : null); assignment.setAreaId(area != null ? area.getId() : null); assignment.setAssetId(asset != null ? asset.getId() : null); assignment.setDeviceId(device.getId()); assignment.setDeviceTypeId(device.getDeviceTypeId()); assignment.setActiveDate(new Date()); assignment.setStatus(request.getStatus() != null ? request.getStatus() : DeviceAssignmentStatus.Active); return assignment; }
area.setAreaTypeId(source.getAreaTypeId()); area.setParentAreaId(source.getParentAreaId()); area.setName(source.getName()); area.setDescription(source.getDescription()); area.setBounds(Location.copy(source.getBounds())); BrandedEntity.copy(source, area); if (isIncludeAreaType()) { area.setAreaType(getDeviceManagement().getAreaType(source.getAreaTypeId())); if (source.getParentAreaId() != null) { IArea parent = getDeviceManagement().getArea(source.getParentAreaId()); area.setParentArea(parent);
@Override public void handleDeviceRegistration(IDeviceRegistrationPayload registration) throws SiteWhereException { Authentication previous = SecurityContextHolder.getContext().getAuthentication(); try { Authentication system = getMicroservice().getSystemUser() .getAuthenticationForTenant(getTenantEngine().getTenant()); SecurityContextHolder.getContext().setAuthentication(system); IDevice device = getOrCreateDevice(registration); // Find assignment metadata that should be associated. ICustomer customer = getCustomerFor(registration); IArea area = getAreaFor(registration); // Make sure device is assigned. if (device.getDeviceAssignmentId() == null) { getLogger().debug("Handling unassigned device for registration."); DeviceAssignmentCreateRequest assnCreate = new DeviceAssignmentCreateRequest(); assnCreate.setDeviceToken(device.getToken()); if (customer != null) { assnCreate.setCustomerToken(customer.getToken()); } if (area != null) { assnCreate.setAreaToken(area.getToken()); } getDeviceManagement().createDeviceAssignment(assnCreate); } boolean isNewRegistration = (device != null); sendRegistrationAck(registration.getDeviceToken(), isNewRegistration); } finally { SecurityContextHolder.getContext().setAuthentication(previous); } }
/** * Common logic for creating a zone based on an incoming request. * * @param request * @param area * @param uuid * @return * @throws SiteWhereException */ public static Zone zoneCreateLogic(IZoneCreateRequest request, IArea area, String uuid) throws SiteWhereException { Zone zone = new Zone(); Persistence.entityCreateLogic(request, zone); zone.setAreaId(area.getId()); zone.setName(request.getName()); zone.setBorderColor(request.getBorderColor()); zone.setFillColor(request.getFillColor()); zone.setOpacity(request.getOpacity()); zone.setBounds(Location.copy(request.getBounds())); return zone; }
/** * Common logic for creating new area object and populating it from request. * * @param request * @param areaType * @param parentArea * @return * @throws SiteWhereException */ public static Area areaCreateLogic(IAreaCreateRequest request, IAreaType areaType, IArea parentArea) throws SiteWhereException { Area area = new Area(); Persistence.brandedEntityCreateLogic(request, area); area.setAreaTypeId(areaType.getId()); area.setParentAreaId(parentArea != null ? parentArea.getId() : null); area.setName(request.getName()); area.setDescription(request.getDescription()); area.setImageUrl(request.getImageUrl()); area.setBounds(Location.copy(request.getBounds())); return area; }
target.setAreaId(area.getId());