This is an automated email from the ASF dual-hosted git repository.

ofuks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8b453ea  [DLAB-1447] Verification of the endpoint url field (#542)
8b453ea is described below

commit 8b453ea8eb145ef12200d4f7fac17bb6d55b3803
Author: Pavel Papou <[email protected]>
AuthorDate: Wed Jan 29 10:44:21 2020 -0500

    [DLAB-1447] Verification of the endpoint url field (#542)
    
    [DLAB-1447] Verification of the endpoint url field
---
 .../java/com/epam/dlab/backendapi/dao/EndpointDAO.java  | 14 ++++++++++++++
 .../com/epam/dlab/backendapi/dao/EndpointDAOImpl.java   | 17 ++++++++++++++++-
 .../backendapi/service/impl/EndpointServiceImpl.java    | 13 ++++++++++++-
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAO.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAO.java
index bb2597b..f28539e 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAO.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAO.java
@@ -24,13 +24,27 @@ import com.epam.dlab.backendapi.domain.EndpointDTO;
 import java.util.List;
 import java.util.Optional;
 
+/**
+ * The interface specifies behaviour for objects, which retrieve, update, 
remove
+ * the endpoints entities from the DataBase, according passed fields, i.e 
name, url, status.
+ */
 public interface EndpointDAO {
        List<EndpointDTO> getEndpoints();
 
        List<EndpointDTO> getEndpointsWithStatus(String status);
 
+       /*** Retrieve the Endpoint entity according required name
+        * @param name - the Endpoint regular title
+        * @return the Optional object
+        */
        Optional<EndpointDTO> get(String name);
 
+       /*** Retrieve the Endpoint entity according required Endpoint URL
+        * @param url - the Endpoint web address
+        * @return the Optional object
+        */
+       Optional<EndpointDTO> getEndpointWithUrl(String url);
+
        void create(EndpointDTO endpointDTO);
 
        void updateEndpointStatus(String name, String status);
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAOImpl.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAOImpl.java
index 5dc9e46..02a67bb 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAOImpl.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/EndpointDAOImpl.java
@@ -25,14 +25,18 @@ import org.bson.conversions.Bson;
 
 import java.util.List;
 import java.util.Optional;
+import java.util.regex.Pattern;
 
 import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.regex;
+
 
 public class EndpointDAOImpl extends BaseDAO implements EndpointDAO {
 
        private static final String ENDPOINTS_COLLECTION = "endpoints";
        private static final String ENDPOINT_NAME_FIELD = "name";
        private static final String ENDPOINT_STATUS_FIELD = "status";
+       private static final String ENDPOINT_URL_FIELD = "url";
 
        @Override
        public List<EndpointDTO> getEndpoints() {
@@ -45,6 +49,11 @@ public class EndpointDAOImpl extends BaseDAO implements 
EndpointDAO {
        }
 
        @Override
+       public Optional<EndpointDTO> getEndpointWithUrl(String url) {
+               return findOne(ENDPOINTS_COLLECTION, endpointUrlCondition(url), 
EndpointDTO.class);
+       }
+
+       @Override
        public Optional<EndpointDTO> get(String name) {
                return findOne(ENDPOINTS_COLLECTION, endpointCondition(name), 
EndpointDTO.class);
        }
@@ -66,7 +75,13 @@ public class EndpointDAOImpl extends BaseDAO implements 
EndpointDAO {
        }
 
        private Bson endpointCondition(String name) {
-               return eq(ENDPOINT_NAME_FIELD, name);
+               Pattern endPointName = Pattern.compile(name, 
Pattern.CASE_INSENSITIVE);
+               return regex(ENDPOINT_NAME_FIELD, endPointName);
+       }
+
+       private Bson endpointUrlCondition(String url) {
+               Pattern endPointUrl = Pattern.compile(url, 
Pattern.CASE_INSENSITIVE);
+               return regex(ENDPOINT_URL_FIELD, endPointUrl);
        }
 
        private Bson endpointStatusCondition(String status) {
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java
index a8e1177..4880fbc 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java
@@ -27,6 +27,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -76,8 +77,18 @@ public class EndpointServiceImpl implements EndpointService {
                                .orElseThrow(() -> new 
ResourceNotFoundException("Endpoint with name " + name + " not found"));
        }
 
+       /**
+        * Create new endpoint object in the System.
+        * The Endpoint objects should contain Unique values of the 'url' and 
'name' fields,
+        * i.e two objects with same URLs should not be created in the system.
+        * @param userInfo user properties
+        * @param endpointDTO object with endpoint fields
+        */
        @Override
        public void create(UserInfo userInfo, EndpointDTO endpointDTO) {
+               
if(endpointDAO.getEndpointWithUrl(endpointDTO.getUrl()).isPresent()) {
+                   throw new ResourceConflictException("The Endpoint URL with 
this address already exists in system");
+               }
                CloudProvider cloudProvider = checkUrl(userInfo, 
endpointDTO.getUrl());
                if (!endpointDAO.get(endpointDTO.getName()).isPresent()) {
                        if (!Objects.nonNull(cloudProvider)) {
@@ -87,7 +98,7 @@ public class EndpointServiceImpl implements EndpointService {
                                        endpointDTO.getTag(), 
EndpointDTO.EndpointStatus.ACTIVE, cloudProvider));
                        userRoleDao.updateMissingRoles(cloudProvider);
                } else {
-                       throw new ResourceConflictException("Endpoint with 
passed name already exist in system");
+                       throw new ResourceConflictException("The Endpoint with 
this name already exists in system");
                }
        }
 


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

Reply via email to