You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by GitBox <gi...@apache.org> on 2022/05/17 12:26:25 UTC

[GitHub] [unomi] jsinovassin opened a new pull request, #424: UNOMI-395 : add endpoint to store scopes

jsinovassin opened a new pull request, #424:
URL: https://github.com/apache/unomi/pull/424

   https://issues.apache.org/jira/browse/UNOMI-395


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan commented on a diff in pull request #424: UNOMI-395 : add endpoint to store scopes

Posted by GitBox <gi...@apache.org>.
jkevan commented on code in PR #424:
URL: https://github.com/apache/unomi/pull/424#discussion_r876784198


##########
services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services.impl.scope;
+
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Scope;
+import org.apache.unomi.api.services.ScopeService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class ScopeServiceImpl implements ScopeService {
+
+    private PersistenceService persistenceService;
+
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
+    }
+
+    @Override
+    public PartialList<Metadata> getScopesMetadatas(int offset, int size, String sortBy) {
+        PartialList<Scope> items = persistenceService.getAllItems(Scope.class, offset, size, sortBy);
+        List<Metadata> details = new LinkedList<>();
+        for (Scope definition : items.getList()) {
+            details.add(definition.getMetadata());
+        }
+        return new PartialList<>(details, items.getOffset(), items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
+    }
+
+    @Override
+    public void save(Scope scope) {
+        if (persistenceService.save(scope)) {
+            persistenceService.refreshIndex(Scope.class, null);

Review Comment:
   Why is there is manual refresh here ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan merged pull request #424: UNOMI-395 : add endpoint to store scopes

Posted by GitBox <gi...@apache.org>.
jkevan merged PR #424:
URL: https://github.com/apache/unomi/pull/424


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan commented on a diff in pull request #424: UNOMI-395 : add endpoint to store scopes

Posted by GitBox <gi...@apache.org>.
jkevan commented on code in PR #424:
URL: https://github.com/apache/unomi/pull/424#discussion_r876839109


##########
services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services.impl.scope;
+
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Scope;
+import org.apache.unomi.api.services.SchedulerService;
+import org.apache.unomi.api.services.ScopeService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class ScopeServiceImpl implements ScopeService {
+
+    private PersistenceService persistenceService;
+
+    private SchedulerService schedulerService;
+
+    private Integer scopesRefreshInterval = 1000;
+
+    private ConcurrentMap<String, Scope> scopes = new ConcurrentHashMap<>();
+
+    private ScheduledFuture<?> scheduledFuture;
+
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
+    }
+
+    public void setSchedulerService(SchedulerService schedulerService) {
+        this.schedulerService = schedulerService;
+    }
+
+    public void setScopesRefreshInterval(Integer scopesRefreshInterval) {
+        this.scopesRefreshInterval = scopesRefreshInterval;
+    }
+
+    public void postConstruct() {
+        initializeTimers();
+    }
+
+    public void preDestroy() {
+        scheduledFuture.cancel(true);
+    }
+
+    @Override
+    public PartialList<Metadata> getScopesMetadatas(int offset, int size, String sortBy) {
+        PartialList<Scope> items = persistenceService.getAllItems(Scope.class, offset, size, sortBy);
+        List<Metadata> details = new LinkedList<>();
+        for (Scope definition : items.getList()) {
+            details.add(definition.getMetadata());
+        }
+        return new PartialList<>(details, items.getOffset(), items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
+    }

Review Comment:
   Since we are loading the scopes in RAM, I'm not sure it's interesting to keep this query.
   We should return the list of in RAM Scopes, witch make the parameters like: int offset, int size, String sortBy obsolete.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan commented on a diff in pull request #424: UNOMI-395 : add endpoint to store scopes

Posted by GitBox <gi...@apache.org>.
jkevan commented on code in PR #424:
URL: https://github.com/apache/unomi/pull/424#discussion_r876806578


##########
services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services.impl.scope;
+
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Scope;
+import org.apache.unomi.api.services.SchedulerService;
+import org.apache.unomi.api.services.ScopeService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TimerTask;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class ScopeServiceImpl implements ScopeService {
+
+    private PersistenceService persistenceService;
+
+    private SchedulerService schedulerService;
+
+    private Integer scopesRefreshInterval = 1000;
+
+    private Map<String, Scope> scopes = new HashMap<>();

Review Comment:
   Should be a concurrent map



##########
services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services.impl.scope;
+
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Scope;
+import org.apache.unomi.api.services.SchedulerService;
+import org.apache.unomi.api.services.ScopeService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TimerTask;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class ScopeServiceImpl implements ScopeService {
+
+    private PersistenceService persistenceService;
+
+    private SchedulerService schedulerService;
+
+    private Integer scopesRefreshInterval = 1000;
+
+    private Map<String, Scope> scopes = new HashMap<>();
+
+    private ScheduledFuture<?> scheduledFuture;
+
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
+    }
+
+    public void setSchedulerService(SchedulerService schedulerService) {
+        this.schedulerService = schedulerService;
+    }
+
+    public void setScopesRefreshInterval(Integer scopesRefreshInterval) {
+        this.scopesRefreshInterval = scopesRefreshInterval;
+    }
+
+    public void postConstruct() {
+        initializeTimers();
+    }
+
+    public void preDestroy() {
+        scheduledFuture.cancel(true);
+    }
+
+    @Override
+    public PartialList<Metadata> getScopesMetadatas(int offset, int size, String sortBy) {
+        PartialList<Scope> items = persistenceService.getAllItems(Scope.class, offset, size, sortBy);
+        List<Metadata> details = new LinkedList<>();
+        for (Scope definition : items.getList()) {
+            details.add(definition.getMetadata());
+        }
+        return new PartialList<>(details, items.getOffset(), items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
+    }
+
+    @Override
+    public void save(Scope scope) {
+        if (persistenceService.save(scope)) {
+            scopes.put(scope.getItemId(), scope);
+        }
+    }
+
+    @Override
+    public boolean delete(String id) {
+        if (persistenceService.remove(id, Scope.class)) {
+            scopes.remove(id);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public Scope getScope(String id) {
+        return persistenceService.load(id, Scope.class);

Review Comment:
   What the poiint of having in memory loaded stuff if we are reading the database here ?



##########
services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services.impl.scope;
+
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Scope;
+import org.apache.unomi.api.services.SchedulerService;
+import org.apache.unomi.api.services.ScopeService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TimerTask;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class ScopeServiceImpl implements ScopeService {
+
+    private PersistenceService persistenceService;
+
+    private SchedulerService schedulerService;
+
+    private Integer scopesRefreshInterval = 1000;
+
+    private Map<String, Scope> scopes = new HashMap<>();
+
+    private ScheduledFuture<?> scheduledFuture;
+
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
+    }
+
+    public void setSchedulerService(SchedulerService schedulerService) {
+        this.schedulerService = schedulerService;
+    }
+
+    public void setScopesRefreshInterval(Integer scopesRefreshInterval) {
+        this.scopesRefreshInterval = scopesRefreshInterval;
+    }
+
+    public void postConstruct() {
+        initializeTimers();
+    }
+
+    public void preDestroy() {
+        scheduledFuture.cancel(true);
+    }
+
+    @Override
+    public PartialList<Metadata> getScopesMetadatas(int offset, int size, String sortBy) {
+        PartialList<Scope> items = persistenceService.getAllItems(Scope.class, offset, size, sortBy);
+        List<Metadata> details = new LinkedList<>();
+        for (Scope definition : items.getList()) {
+            details.add(definition.getMetadata());
+        }
+        return new PartialList<>(details, items.getOffset(), items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
+    }
+
+    @Override
+    public void save(Scope scope) {
+        if (persistenceService.save(scope)) {
+            scopes.put(scope.getItemId(), scope);

Review Comment:
   Nothing should change the map other than the refresh to avoid concurrency issues.



##########
services/src/main/java/org/apache/unomi/services/impl/scope/ScopeServiceImpl.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.services.impl.scope;
+
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.Scope;
+import org.apache.unomi.api.services.SchedulerService;
+import org.apache.unomi.api.services.ScopeService;
+import org.apache.unomi.persistence.spi.PersistenceService;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TimerTask;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class ScopeServiceImpl implements ScopeService {
+
+    private PersistenceService persistenceService;
+
+    private SchedulerService schedulerService;
+
+    private Integer scopesRefreshInterval = 1000;
+
+    private Map<String, Scope> scopes = new HashMap<>();
+
+    private ScheduledFuture<?> scheduledFuture;
+
+    public void setPersistenceService(PersistenceService persistenceService) {
+        this.persistenceService = persistenceService;
+    }
+
+    public void setSchedulerService(SchedulerService schedulerService) {
+        this.schedulerService = schedulerService;
+    }
+
+    public void setScopesRefreshInterval(Integer scopesRefreshInterval) {
+        this.scopesRefreshInterval = scopesRefreshInterval;
+    }
+
+    public void postConstruct() {
+        initializeTimers();
+    }
+
+    public void preDestroy() {
+        scheduledFuture.cancel(true);
+    }
+
+    @Override
+    public PartialList<Metadata> getScopesMetadatas(int offset, int size, String sortBy) {
+        PartialList<Scope> items = persistenceService.getAllItems(Scope.class, offset, size, sortBy);
+        List<Metadata> details = new LinkedList<>();
+        for (Scope definition : items.getList()) {
+            details.add(definition.getMetadata());
+        }
+        return new PartialList<>(details, items.getOffset(), items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
+    }
+
+    @Override
+    public void save(Scope scope) {
+        if (persistenceService.save(scope)) {
+            scopes.put(scope.getItemId(), scope);
+        }
+    }
+
+    @Override
+    public boolean delete(String id) {
+        if (persistenceService.remove(id, Scope.class)) {
+            scopes.remove(id);

Review Comment:
   Nothing should change the map other than the refresh to avoid concurrency issues.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org