RodrigoDLopez commented on a change in pull request #5103:
URL: https://github.com/apache/cloudstack/pull/5103#discussion_r680171003



##########
File path: 
api/src/main/java/org/apache/cloudstack/api/command/admin/annotation/ListAnnotationsCmd.java
##########
@@ -41,11 +41,24 @@
 
     @Parameter(name = ApiConstants.ID, type = CommandType.STRING, description 
= "the id of the annotation")
     private String uuid;
+
     @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, 
description = "the entity type")
     private String entityType;
+
     @Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, 
description = "the id of the entity for which to show annotations")
     private String entityUuid;
 
+    @Parameter(name = ApiConstants.USER_ID, type = CommandType.STRING,

Review comment:
       maybe here too

##########
File path: 
engine/schema/src/main/java/org/apache/cloudstack/annotation/dao/AnnotationDaoImpl.java
##########
@@ -29,31 +32,89 @@
  */
 @Component
 public class AnnotationDaoImpl extends GenericDaoBase<AnnotationVO, Long> 
implements AnnotationDao {
-    private final SearchBuilder<AnnotationVO> AnnotationSearchByType;
-    private final SearchBuilder<AnnotationVO> AnnotationSearchByTypeAndUuid;
+    private final SearchBuilder<AnnotationVO> AnnotationSearchBuilder;
+    private final GenericSearchBuilder<AnnotationVO, Long> 
AnnotationCountSearchBuilder;
 
     public AnnotationDaoImpl() {
         super();
-        AnnotationSearchByType = createSearchBuilder();
-        AnnotationSearchByType.and("entityType", 
AnnotationSearchByType.entity().getEntityType(), SearchCriteria.Op.EQ);
-        AnnotationSearchByType.done();
-        AnnotationSearchByTypeAndUuid = createSearchBuilder();
-        AnnotationSearchByTypeAndUuid.and("entityType", 
AnnotationSearchByTypeAndUuid.entity().getEntityType(), SearchCriteria.Op.EQ);
-        AnnotationSearchByTypeAndUuid.and("entityUuid", 
AnnotationSearchByTypeAndUuid.entity().getEntityUuid(), SearchCriteria.Op.EQ);
-        AnnotationSearchByTypeAndUuid.done();
+        AnnotationSearchBuilder = createSearchBuilder();
+        AnnotationSearchBuilder.and("entityType", 
AnnotationSearchBuilder.entity().getEntityType(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("entityUuid", 
AnnotationSearchBuilder.entity().getEntityUuid(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("userUuid", 
AnnotationSearchBuilder.entity().getUserUuid(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("adminsOnly", 
AnnotationSearchBuilder.entity().getUserUuid(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("annotation", 
AnnotationSearchBuilder.entity().getAnnotation(), SearchCriteria.Op.LIKE);
+        AnnotationSearchBuilder.done();
 
+        AnnotationCountSearchBuilder = createSearchBuilder(Long.class);
+        AnnotationCountSearchBuilder.select(null, SearchCriteria.Func.COUNT, 
AnnotationCountSearchBuilder.entity().getId());
+        AnnotationCountSearchBuilder.and("entityType", 
AnnotationCountSearchBuilder.entity().getEntityType(), SearchCriteria.Op.EQ);
+        AnnotationCountSearchBuilder.and("entityUuid", 
AnnotationCountSearchBuilder.entity().getEntityUuid(), SearchCriteria.Op.EQ);
+        AnnotationCountSearchBuilder.done();
     }
 
-    @Override public List<AnnotationVO> findByEntityType(String entityType) {
-        SearchCriteria<AnnotationVO> sc = createSearchCriteria();
+    private List<AnnotationVO> 
listAnnotationsOrderedByCreatedDate(SearchCriteria<AnnotationVO> sc) {
+        Filter filter = new Filter(AnnotationVO.class, "created", false, null, 
null);
+        return listBy(sc, filter);
+    }
+
+    @Override public List<AnnotationVO> listByEntityType(String entityType, 
String userUuid, boolean isCallerAdmin, String annotationFilter, String 
callingUserUuid, String keyword) {

Review comment:
       I know that this is not a big thing. But i think it's better read this 
in two separate lines.
   ```
   @Override
   public List [...]
   ```
   

##########
File path: 
api/src/main/java/org/apache/cloudstack/api/command/admin/annotation/AddAnnotationCmd.java
##########
@@ -40,11 +41,17 @@
 
     @Parameter(name = ApiConstants.ANNOTATION, type = CommandType.STRING, 
description = "the annotation text")
     private String annotation;
+
     @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, 
description = "the entity type (only HOST is allowed atm)")
     private String entityType;
+
     @Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, 
description = "the id of the entity to annotate")
     private String entityUuid;
 
+    @Parameter(name = ApiConstants.ADMINS_ONLY, type = CommandType.BOOLEAN,

Review comment:
       wouldn't it be better if we add the flag since on this new parameter

##########
File path: 
engine/schema/src/main/java/org/apache/cloudstack/annotation/dao/AnnotationDaoImpl.java
##########
@@ -29,31 +32,89 @@
  */
 @Component
 public class AnnotationDaoImpl extends GenericDaoBase<AnnotationVO, Long> 
implements AnnotationDao {
-    private final SearchBuilder<AnnotationVO> AnnotationSearchByType;
-    private final SearchBuilder<AnnotationVO> AnnotationSearchByTypeAndUuid;
+    private final SearchBuilder<AnnotationVO> AnnotationSearchBuilder;
+    private final GenericSearchBuilder<AnnotationVO, Long> 
AnnotationCountSearchBuilder;
 
     public AnnotationDaoImpl() {
         super();
-        AnnotationSearchByType = createSearchBuilder();
-        AnnotationSearchByType.and("entityType", 
AnnotationSearchByType.entity().getEntityType(), SearchCriteria.Op.EQ);
-        AnnotationSearchByType.done();
-        AnnotationSearchByTypeAndUuid = createSearchBuilder();
-        AnnotationSearchByTypeAndUuid.and("entityType", 
AnnotationSearchByTypeAndUuid.entity().getEntityType(), SearchCriteria.Op.EQ);
-        AnnotationSearchByTypeAndUuid.and("entityUuid", 
AnnotationSearchByTypeAndUuid.entity().getEntityUuid(), SearchCriteria.Op.EQ);
-        AnnotationSearchByTypeAndUuid.done();
+        AnnotationSearchBuilder = createSearchBuilder();
+        AnnotationSearchBuilder.and("entityType", 
AnnotationSearchBuilder.entity().getEntityType(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("entityUuid", 
AnnotationSearchBuilder.entity().getEntityUuid(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("userUuid", 
AnnotationSearchBuilder.entity().getUserUuid(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("adminsOnly", 
AnnotationSearchBuilder.entity().getUserUuid(), SearchCriteria.Op.EQ);
+        AnnotationSearchBuilder.and("annotation", 
AnnotationSearchBuilder.entity().getAnnotation(), SearchCriteria.Op.LIKE);
+        AnnotationSearchBuilder.done();
 
+        AnnotationCountSearchBuilder = createSearchBuilder(Long.class);
+        AnnotationCountSearchBuilder.select(null, SearchCriteria.Func.COUNT, 
AnnotationCountSearchBuilder.entity().getId());
+        AnnotationCountSearchBuilder.and("entityType", 
AnnotationCountSearchBuilder.entity().getEntityType(), SearchCriteria.Op.EQ);
+        AnnotationCountSearchBuilder.and("entityUuid", 
AnnotationCountSearchBuilder.entity().getEntityUuid(), SearchCriteria.Op.EQ);
+        AnnotationCountSearchBuilder.done();
     }
 
-    @Override public List<AnnotationVO> findByEntityType(String entityType) {
-        SearchCriteria<AnnotationVO> sc = createSearchCriteria();
+    private List<AnnotationVO> 
listAnnotationsOrderedByCreatedDate(SearchCriteria<AnnotationVO> sc) {
+        Filter filter = new Filter(AnnotationVO.class, "created", false, null, 
null);
+        return listBy(sc, filter);
+    }
+
+    @Override public List<AnnotationVO> listByEntityType(String entityType, 
String userUuid, boolean isCallerAdmin, String annotationFilter, String 
callingUserUuid, String keyword) {
+        SearchCriteria<AnnotationVO> sc = AnnotationSearchBuilder.create();
         sc.addAnd("entityType", SearchCriteria.Op.EQ, entityType);
-        return listBy(sc);
+        if (StringUtils.isNotBlank(userUuid)) {
+            sc.addAnd("userUuid", SearchCriteria.Op.EQ, userUuid);
+        }
+        if (!isCallerAdmin) {
+            sc.addAnd("adminsOnly", SearchCriteria.Op.EQ, false);
+        }
+        if (StringUtils.isNotBlank(keyword)) {
+            sc.setParameters("annotation", "%" + keyword + "%");
+        }
+        return listAnnotationsOrderedByCreatedDate(sc);
     }
 
-    @Override public List<AnnotationVO> findByEntity(String entityType, String 
entityUuid) {
-        SearchCriteria<AnnotationVO> sc = createSearchCriteria();
+    @Override public List<AnnotationVO> listByEntity(String entityType, String 
entityUuid, String userUuid,

Review comment:
       if you consider change the other one. This one need to be changed too
   ```
   @Override
   public List [...]
   ```




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to