aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/AttributeResource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/api/resource/AttributeResource.java')
-rw-r--r--src/org/traccar/api/resource/AttributeResource.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/org/traccar/api/resource/AttributeResource.java b/src/org/traccar/api/resource/AttributeResource.java
index 4d326779b..7b81d3ffb 100644
--- a/src/org/traccar/api/resource/AttributeResource.java
+++ b/src/org/traccar/api/resource/AttributeResource.java
@@ -38,6 +38,7 @@ import org.traccar.api.BaseResource;
import org.traccar.database.AttributesManager;
import org.traccar.model.Attribute;
import org.traccar.model.Position;
+import org.traccar.model.User;
import org.traccar.processing.ComputedAttributesHandler;
@Path("attributes/computed")
@@ -52,42 +53,43 @@ public class AttributeResource extends BaseResource {
AttributesManager attributesManager = Context.getAttributesManager();
if (refresh) {
- attributesManager.refreshAttributes();
+ attributesManager.refreshItems();
}
Set<Long> result = new HashSet<>();
if (all) {
if (Context.getPermissionsManager().isAdmin(getUserId())) {
- result.addAll(attributesManager.getAllAttributes());
+ result.addAll(attributesManager.getAllItems());
} else {
Context.getPermissionsManager().checkManager(getUserId());
- result.addAll(attributesManager.getManagedAttributes(getUserId()));
+ result.addAll(attributesManager.getManagedItems(getUserId()));
}
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- result.addAll(attributesManager.getUserAttributes(userId));
+ result.addAll(attributesManager.getUserItems(userId));
}
if (groupId != 0) {
Context.getPermissionsManager().checkGroup(getUserId(), groupId);
- result.retainAll(attributesManager.getGroupAttributes(groupId));
+ result.retainAll(attributesManager.getGroupItems(groupId));
}
if (deviceId != 0) {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- result.retainAll(attributesManager.getDeviceAttributes(deviceId));
+ result.retainAll(attributesManager.getDeviceItems(deviceId));
}
- return attributesManager.getAttributes(result);
+ return attributesManager.getItems(Attribute.class, result);
}
private Response add(Attribute entity) throws SQLException {
- Context.getAttributesManager().addAttribute(entity);
- Context.getDataManager().linkAttribute(getUserId(), entity.getId());
- Context.getAttributesManager().refreshUserAttributes();
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ Context.getAttributesManager().addItem(entity);
+ Context.getDataManager().linkObject(User.class, getUserId(), entity.getClass(), entity.getId(), true);
+ Context.getAttributesManager().refreshUserItems();
return Response.ok(entity).build();
}
@@ -127,8 +129,8 @@ public class AttributeResource extends BaseResource {
@PUT
public Response update(Attribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkAttribute(getUserId(), entity.getId());
- Context.getAttributesManager().updateAttribute(entity);
+ Context.getPermissionsManager().checkPermission(Attribute.class, getUserId(), entity.getId());
+ Context.getAttributesManager().updateItem(entity);
return Response.ok(entity).build();
}
@@ -136,8 +138,8 @@ public class AttributeResource extends BaseResource {
@DELETE
public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkAttribute(getUserId(), id);
- Context.getAttributesManager().removeAttribute(id);
+ Context.getPermissionsManager().checkPermission(Attribute.class, getUserId(), id);
+ Context.getAttributesManager().removeItem(id);
return Response.noContent().build();
}