|
|
|
|
@ -19,12 +19,11 @@ import de.srsoftware.umbrella.core.api.TagService;
@@ -19,12 +19,11 @@ import de.srsoftware.umbrella.core.api.TagService;
|
|
|
|
|
import de.srsoftware.umbrella.core.api.UserService; |
|
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
|
import de.srsoftware.umbrella.core.model.Token; |
|
|
|
|
import de.srsoftware.umbrella.core.model.UmbrellaUser; |
|
|
|
|
import org.json.JSONArray; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
public class TagModule extends BaseHandler implements TagService { |
|
|
|
|
private final SqliteDb tagDb; |
|
|
|
|
@ -36,6 +35,11 @@ public class TagModule extends BaseHandler implements TagService {
@@ -36,6 +35,11 @@ public class TagModule extends BaseHandler implements TagService {
|
|
|
|
|
users = userService; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void deleteEntity(String module, long entityId) { |
|
|
|
|
tagDb.deleteEntity(module,entityId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean doDelete(Path path, HttpExchange ex) throws IOException { |
|
|
|
|
addCors(ex); |
|
|
|
|
@ -67,8 +71,7 @@ public class TagModule extends BaseHandler implements TagService {
@@ -67,8 +71,7 @@ public class TagModule extends BaseHandler implements TagService {
|
|
|
|
|
if (module == null) throw unprocessable("Module missing in path."); |
|
|
|
|
var head = path.pop(); |
|
|
|
|
long entityId = Long.parseLong(head); |
|
|
|
|
var tags = tagDb.list(user.get().id(),module,entityId); |
|
|
|
|
return sendContent(ex, tags); |
|
|
|
|
return sendContent(ex, getTags(module,entityId,user.get())); |
|
|
|
|
} catch (NumberFormatException e){ |
|
|
|
|
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path."); |
|
|
|
|
} catch (UmbrellaException e){ |
|
|
|
|
@ -99,7 +102,7 @@ public class TagModule extends BaseHandler implements TagService {
@@ -99,7 +102,7 @@ public class TagModule extends BaseHandler implements TagService {
|
|
|
|
|
arr.toList().stream().filter(elem -> elem instanceof Number).map(elem -> (Number) elem).map(Number::longValue).toList() |
|
|
|
|
: List.of(user.get().id()); |
|
|
|
|
if (userList.isEmpty()) throw missingFieldException(USER_LIST); |
|
|
|
|
tag = tagDb.save(userList, module, entityId, tag); |
|
|
|
|
tag = save(module, entityId, userList, tag); |
|
|
|
|
return sendContent(ex, tag); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
return sendContent(ex, HTTP_UNPROCESSABLE, "Entity id missing in path."); |
|
|
|
|
@ -108,5 +111,18 @@ public class TagModule extends BaseHandler implements TagService {
@@ -108,5 +111,18 @@ public class TagModule extends BaseHandler implements TagService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Collection<String> getTags(String module, long entityId, UmbrellaUser user) throws UmbrellaException{ |
|
|
|
|
return tagDb.list(user.id(),module,entityId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags) { |
|
|
|
|
tagDb.save(userIds,module,entityId,tags); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String save(String module, long entityId, Collection<Long> userIds, String tag) { |
|
|
|
|
save(module,entityId,userIds,List.of(tag)); |
|
|
|
|
return tag; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|