ppapou commented on a change in pull request #926:
URL: https://github.com/apache/incubator-datalab/pull/926#discussion_r507293757



##########
File path: 
services/self-service/src/main/java/com/epam/dlab/backendapi/dao/OdahuDAOImpl.java
##########
@@ -77,15 +80,20 @@
 
     @Override
     public OdahuFieldsDTO getFields(String name, String project, String 
endpoint) {
-        Optional<Document> one = findOne(PROJECTS_COLLECTION, 
odahuProjectEndpointCondition(name, project, endpoint),
-                fields(include(ODAHU_FIELD), excludeId()));
-        OdahuFieldsDTO odahuFields = null;
-        if (one.isPresent()) {
-            List<OdahuFieldsDTO> list = 
convertFromDocument(one.get().get(ODAHU_FIELD, ArrayList.class), new 
TypeReference<List<OdahuFieldsDTO>>() {
-            });
-            odahuFields = list.get(0);
-        }
-        return odahuFields;
+        FindIterable<Document> odahuDoc = find(PROJECTS_COLLECTION,
+                odahuProjectEndpointCondition(name, project, endpoint),
+                fields(include(ODAHU_FIELD), excludeId())); //TODO: 
Potentially, method can be improved by filtering the Documents
+
+        Optional<OdahuFieldsDTO> odahuFields;
+        List<OdahuFieldsDTO> odahuFieldsDTOList;
+
+        odahuFieldsDTOList = 
convertFromDocument(odahuDoc.first().get(ODAHU_FIELD, ArrayList.class), new 
TypeReference<List<OdahuFieldsDTO>>() {});
+        odahuFields = odahuFieldsDTOList.stream()
+                .filter(oDTO -> oDTO.getName().equals(name))
+                .findAny();
+        if (odahuFields.isPresent()){
+            return odahuFields.get();
+        } else throw new DlabException("Unable to find the " + name + " 
cluster properties");

Review comment:
       else section has been changed




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to