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 74991cc  [DLAB-1447] Endpoints Fields verification (#576)
74991cc is described below

commit 74991cc6352e9e55a020c1d0fe1f85344ce2d67b
Author: Pavel Papou <[email protected]>
AuthorDate: Tue Feb 4 11:02:23 2020 -0500

    [DLAB-1447] Endpoints Fields verification (#576)
    
    * [DLAB-1447] Endpoints Fields verification
---
 .../epam/dlab/backendapi/dao/EndpointDAOImpl.java    |  4 ++--
 .../backendapi/service/impl/EndpointServiceImpl.java | 20 +++++++++-----------
 2 files changed, 11 insertions(+), 13 deletions(-)

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 02a67bb..aec56ec 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
@@ -75,12 +75,12 @@ public class EndpointDAOImpl extends BaseDAO implements 
EndpointDAO {
        }
 
        private Bson endpointCondition(String name) {
-               Pattern endPointName = Pattern.compile(name, 
Pattern.CASE_INSENSITIVE);
+               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);
+               Pattern endPointUrl = Pattern.compile("^" + url + "$", 
Pattern.CASE_INSENSITIVE);
                return regex(ENDPOINT_URL_FIELD, endPointUrl);
        }
 
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 a4cf90b..1c169bc 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,7 +27,6 @@ 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
@@ -86,20 +85,19 @@ public class EndpointServiceImpl implements EndpointService 
{
         */
        @Override
        public void create(UserInfo userInfo, EndpointDTO endpointDTO) {
+               if (endpointDAO.get(endpointDTO.getName()).isPresent()) {
+                       throw new ResourceConflictException("The Endpoint with 
this name exists in system");
+               }
                
if(endpointDAO.getEndpointWithUrl(endpointDTO.getUrl()).isPresent()) {
-                   throw new ResourceConflictException("The Endpoint URL with 
this address already exists in system");
+                   throw new ResourceConflictException("The Endpoint URL with 
this address exists in system");
                }
                CloudProvider cloudProvider = checkUrl(userInfo, 
endpointDTO.getUrl());
-               if (!endpointDAO.get(endpointDTO.getName()).isPresent()) {
-                       if (!Objects.nonNull(cloudProvider)) {
-                               throw new DlabException("CloudProvider cannot 
be null");
-                       }
-                       endpointDAO.create(new 
EndpointDTO(endpointDTO.getName(), endpointDTO.getUrl(), 
endpointDTO.getAccount(),
-                                       endpointDTO.getTag(), 
EndpointDTO.EndpointStatus.ACTIVE, cloudProvider));
-                       userRoleDao.updateMissingRoles(cloudProvider);
-               } else {
-                       throw new ResourceConflictException("The Endpoint with 
this name already exists in system");
+               if (Objects.isNull(cloudProvider)) {
+                       throw new DlabException("CloudProvider cannot be null");
                }
+               endpointDAO.create(new EndpointDTO(endpointDTO.getName(), 
endpointDTO.getUrl(), endpointDTO.getAccount(),
+                               endpointDTO.getTag(), 
EndpointDTO.EndpointStatus.ACTIVE, cloudProvider));
+               userRoleDao.updateMissingRoles(cloudProvider);
        }
 
        @Override


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

Reply via email to