/** * Creates a JTS polygon based on zone definition. * * @param zone * @return */ public static Polygon createPolygonForZone(IZone zone) { return createPolygonForLocations(zone.getBounds()); }
@Override public URI getAreaTypeIdentifier(IAreaType areaType) throws SiteWhereException { return createUri(SITEWHERE_PROTOCOL + "areatype/" + areaType.getToken()); }
/** * Create a copy of an SPI object. Used by web services for marshaling. * * @param input * @return */ public static Zone copy(IZone input) throws SiteWhereException { Zone result = new Zone(); result.setId(input.getId()); result.setToken(input.getToken()); result.setAreaId(input.getAreaId()); result.setName(input.getName()); result.setCreatedDate(input.getCreatedDate()); result.setBorderColor(input.getBorderColor()); result.setFillColor(input.getFillColor()); result.setOpacity(input.getOpacity()); result.setBounds(Location.copy(input.getBounds())); PersistentEntity.copy(input, result); return result; } }
/** * 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); }
/** * Convert zone from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GZone asGrpcZone(IZone api) throws SiteWhereException { GZone.Builder grpc = GZone.newBuilder(); grpc.setName(api.getName()); grpc.addAllBounds(CommonModelConverter.asGrpcLocations(api.getBounds())); grpc.setFillColor(api.getFillColor()); grpc.setBorderColor(api.getBorderColor()); grpc.setOpacity(api.getOpacity()); grpc.setEntityInformation(CommonModelConverter.asGrpcEntityInformation(api)); return grpc.build(); }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IZone source, Document target) { target.append(PROP_AREA_ID, source.getAreaId()); target.append(PROP_NAME, source.getName()); target.append(PROP_BORDER_COLOR, source.getBorderColor()); target.append(PROP_FILL_COLOR, source.getFillColor()); target.append(PROP_OPACITY, source.getOpacity()); MongoBoundedEntity.saveBounds(source, target); MongoPersistentEntity.toDocument(source, target); }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IAreaType source, Document target) { target.append(PROP_NAME, source.getName()); target.append(PROP_DESCRIPTION, source.getDescription()); target.append(PROP_CONTAINED_AREA_TYPE_IDS, source.getContainedAreaTypeIds()); MongoBrandedEntity.toDocument(source, target); }
public Builder(IAreaType api) { request.setToken(api.getToken()); request.setName(api.getName()); request.setDescription(api.getDescription()); request.setIcon(api.getIcon()); if (api.getMetadata() != null) { request.setMetadata(new HashMap<String, String>()); request.getMetadata().putAll(api.getMetadata()); } }
/** * 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; }
@Override public URI getAreaIdentifier(IArea area) throws SiteWhereException { return createUri(SITEWHERE_PROTOCOL + "area/" + area.getToken()); }
public <T extends IZone> ZoneMatcher(IDeviceLocation location, List<T> zones) { this.location = location; for (IZone zone : zones) { Polygon zonePoly = GeoUtils.createPolygonForZone(zone); ZoneContainment containment = (zonePoly.contains(GeoUtils.createPointForLocation(location))) ? ZoneContainment.Inside : ZoneContainment.Outside; ZoneRelationship relationship = new ZoneRelationship(location, zone, containment); relationships.put(zone.getToken(), relationship); } }
@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 a list of area type tokens to ids. * * @param tokens * @return * @throws SiteWhereException */ protected List<UUID> convertAreaTypeTokensToIds(List<String> tokens) throws SiteWhereException { List<UUID> catids = new ArrayList<>(); if (tokens != null) { for (String token : tokens) { IAreaType contained = getAreaTypeByToken(token); if (contained != null) { catids.add(contained.getId()); } } } return catids; }
/** * Save coordinates to a document. * * @param source * @param target */ public static void saveBounds(IBoundedEntity source, Document target) { ArrayList<Document> coords = new ArrayList<Document>(); if (source.getBounds() != null) { for (ILocation location : source.getBounds()) { Document coord = new Document(); coord.put(PROP_LATITUDE, location.getLatitude()); coord.put(PROP_LONGITUDE, location.getLongitude()); if (location.getElevation() != null) { coord.put(PROP_ELEVATION, location.getElevation()); } coords.add(coord); } } target.append(PROP_COORDINATES, coords); }
/** * 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(); }
/** * Convert area type from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GAreaType asGrpcAreaType(IAreaType api) throws SiteWhereException { GAreaType.Builder grpc = GAreaType.newBuilder(); grpc.setName(api.getName()); grpc.setDescription(api.getDescription()); if (api.getContainedAreaTypeIds() != null) { grpc.addAllContainedAreaTypeIds(CommonModelConverter.asGrpcUuids(api.getContainedAreaTypeIds())); } 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; }