From a537271f63936d5293abaca0846593b08d1c0b9d Mon Sep 17 00:00:00 2001 From: Jean Pimentel Date: Wed, 2 Oct 2019 17:58:09 -0300 Subject: [PATCH 1/4] Add category on Technology --- .../techgallery/persistence/model/Technology.java | 12 ++++++++++++ .../techgallery/service/model/TechnologyTO.java | 10 ++++++++++ .../service/transformer/TechnologyTransformer.java | 2 ++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/com/ciandt/techgallery/persistence/model/Technology.java b/src/main/java/com/ciandt/techgallery/persistence/model/Technology.java index 1e4da779..ac785df3 100644 --- a/src/main/java/com/ciandt/techgallery/persistence/model/Technology.java +++ b/src/main/java/com/ciandt/techgallery/persistence/model/Technology.java @@ -44,6 +44,7 @@ public class Technology extends BaseEntity { public static final String LAST_ACTIVITY = "lastActivity"; public static final String UPDATE_USER = "updateUser"; public static final String ACTIVE = "active"; + public static final String CATEGORY = "category"; /* * Attributes -------------------------------------------- @@ -112,6 +113,9 @@ public class Technology extends BaseEntity { @Ignore private String imageContent; + @Index + private String category; + /* * Getter's and Setter's -------------------------------------------- */ @@ -289,6 +293,14 @@ public void setIdBoard(String idBoard) { this.idBoard = idBoard; } + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + /* * Methods -------------------------------------------- */ diff --git a/src/main/java/com/ciandt/techgallery/service/model/TechnologyTO.java b/src/main/java/com/ciandt/techgallery/service/model/TechnologyTO.java index c6982417..9f5086f2 100644 --- a/src/main/java/com/ciandt/techgallery/service/model/TechnologyTO.java +++ b/src/main/java/com/ciandt/techgallery/service/model/TechnologyTO.java @@ -48,6 +48,8 @@ public class TechnologyTO implements Response { private String idBoard; /** technology smart canvas board id */ private String boardUrlPrefix; + /** technology category */ + private String category; private Date lastActivity; @@ -204,4 +206,12 @@ public String getBoardUrlPrefix() { public void setBoardUrlPrefix(String boardUrlPrefix) { this.boardUrlPrefix = boardUrlPrefix; } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } } diff --git a/src/main/java/com/ciandt/techgallery/service/transformer/TechnologyTransformer.java b/src/main/java/com/ciandt/techgallery/service/transformer/TechnologyTransformer.java index b308f6e6..f07a9da1 100644 --- a/src/main/java/com/ciandt/techgallery/service/transformer/TechnologyTransformer.java +++ b/src/main/java/com/ciandt/techgallery/service/transformer/TechnologyTransformer.java @@ -26,6 +26,7 @@ public Technology transformFrom(TechnologyTO baseObject) { product.setLastActivity(baseObject.getLastActivity()); product.setImageContent(baseObject.getImageContent()); product.setIdBoard(baseObject.getIdBoard()); + product.setCategory(baseObject.getCategory()); if(baseObject.getProject() != null) { ProjectTransformer projectTransformer = new ProjectTransformer(); @@ -57,6 +58,7 @@ public TechnologyTO transformTo(Technology baseObject) { product.setImageContent(baseObject.getImageContent()); product.setIdBoard(baseObject.getIdBoard()); product.setBoardUrlPrefix(System.getProperty("board.url.prefix")); + product.setCategory(baseObject.getCategory()); if(baseObject.getProject() != null) { ProjectTransformer projectTransformer = new ProjectTransformer(); From 4c412544ad74f722ba19f1882432fb25fad94cf8 Mon Sep 17 00:00:00 2001 From: Jean Pimentel Date: Wed, 2 Oct 2019 17:59:27 -0300 Subject: [PATCH 2/4] Add category (null or blank) validation. --- .../service/TechnologyService.java | 5 +++- .../service/enums/TechnologyCategoryEnum.java | 26 ++++++++++++++++++ .../service/enums/ValidationMessageEnums.java | 2 ++ .../service/impl/TechnologyServiceImpl.java | 26 ++++++++++++++++++ .../i18n/Tech_Gallery_en_US.properties | 2 ++ .../service/TechnologyServiceTest.java | 27 +++++++++++++++++++ .../technology/ShareTechnologyTest.java | 7 +++++ 7 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/ciandt/techgallery/service/enums/TechnologyCategoryEnum.java diff --git a/src/main/java/com/ciandt/techgallery/service/TechnologyService.java b/src/main/java/com/ciandt/techgallery/service/TechnologyService.java index c5e68e44..62986634 100644 --- a/src/main/java/com/ciandt/techgallery/service/TechnologyService.java +++ b/src/main/java/com/ciandt/techgallery/service/TechnologyService.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.util.List; +import java.util.Map; /** * Services for Technologies. @@ -102,7 +103,7 @@ void audit(String technologyId, User user) /** * Service to delete a technology. * - * @param technology entity id. + * @param technologyId entity id. * @return Technology or message error. * @throws InternalServerErrorException . * @throws BadRequestException . @@ -110,4 +111,6 @@ void audit(String technologyId, User user) Technology deleteTechnology(final String technologyId, User user) throws InternalServerErrorException, BadRequestException, NotFoundException, OAuthRequestException; + + Map getCategories(); } diff --git a/src/main/java/com/ciandt/techgallery/service/enums/TechnologyCategoryEnum.java b/src/main/java/com/ciandt/techgallery/service/enums/TechnologyCategoryEnum.java new file mode 100644 index 00000000..b24a2e7c --- /dev/null +++ b/src/main/java/com/ciandt/techgallery/service/enums/TechnologyCategoryEnum.java @@ -0,0 +1,26 @@ +package com.ciandt.techgallery.service.enums; + +public enum TechnologyCategoryEnum { + + TECHNIQUE("technique", "Technique"), + TOOL("tool", "Tools"), + LANGUAGE("language", "Language"), + FRAMEWORK("framework", "Framework"), + PLATFORM("platform", "Platform"); + + private String id; + private String title; + + TechnologyCategoryEnum(String id, String title) { + this.id = id; + this.title = title; + } + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } +} diff --git a/src/main/java/com/ciandt/techgallery/service/enums/ValidationMessageEnums.java b/src/main/java/com/ciandt/techgallery/service/enums/ValidationMessageEnums.java index 1ae97515..948303dc 100644 --- a/src/main/java/com/ciandt/techgallery/service/enums/ValidationMessageEnums.java +++ b/src/main/java/com/ciandt/techgallery/service/enums/ValidationMessageEnums.java @@ -21,6 +21,8 @@ public enum ValidationMessageEnums { TECHNOLOGY_NAME_ALREADY_USED("Technology already exists with this name."), TECHNOLOGY_NOT_EXIST("Technology doesn't exist."), TECHNOLOGY_NAME_CANNOT_CHANGE("Technology's name cannot be changed."), + TECHNOLOGY_CATEGORY_BLANK("Technology's category cannot be null or blank."), + TECHNOLOGY_CATEGORY_INVALID("Technology's category must be valid. Valid categories: %s. %s given."), // Message for users USER_CANNOT_BLANK("User or user's id cannot be null or blank."), USER_NOT_EXIST("User doesn't exist."), diff --git a/src/main/java/com/ciandt/techgallery/service/impl/TechnologyServiceImpl.java b/src/main/java/com/ciandt/techgallery/service/impl/TechnologyServiceImpl.java index 06a581a6..db359a44 100644 --- a/src/main/java/com/ciandt/techgallery/service/impl/TechnologyServiceImpl.java +++ b/src/main/java/com/ciandt/techgallery/service/impl/TechnologyServiceImpl.java @@ -6,13 +6,16 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import javax.xml.bind.DatatypeConverter; import com.ciandt.techgallery.filters.NamespaceFilter; import com.ciandt.techgallery.persistence.model.Project; +import com.ciandt.techgallery.service.enums.TechnologyCategoryEnum; import com.google.appengine.api.NamespaceManager; import org.apache.commons.lang.StringUtils; @@ -109,6 +112,7 @@ private void updateTechnology(Technology foundTechnology, Technology technology, foundTechnology.setLastActivityUser(getSafeEmail(user)); foundTechnology.setIdBoard(technology.getIdBoard()); foundTechnology.setProject(technology.getProject()); + foundTechnology.setCategory(technology.getCategory()); technologyDAO.update(foundTechnology); @@ -160,6 +164,19 @@ private Technology validateInformations(Technology technology) throws BadRequest throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_SHORT_DESCRIPTION_BLANK.message()); } else if (StringUtils.isBlank(technology.getDescription())) { throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_DESCRIPTION_BLANK.message()); + } else if (StringUtils.isBlank(technology.getCategory())) { + throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_CATEGORY_BLANK.message()); + } + + Map categories = getCategories(); + if(!categories.containsKey(technology.getCategory())) { + throw new BadRequestException( + String.format( + ValidationMessageEnums.TECHNOLOGY_CATEGORY_INVALID.message(), + String.join(", ", categories.keySet()), + technology.getCategory() + ) + ); } Technology dbTechnology = technologyDAO.findByName(technology.getName()); @@ -480,4 +497,13 @@ public Technology deleteTechnology(String technologyId, User user) technologyDAO.update(technology); return technology; } + + @Override + public Map getCategories() { + Map categories = new HashMap<>(); + for (TechnologyCategoryEnum category : TechnologyCategoryEnum.values()) { + categories.put(category.getId(), category.getTitle()); + } + return categories; + } } diff --git a/src/main/resources/i18n/Tech_Gallery_en_US.properties b/src/main/resources/i18n/Tech_Gallery_en_US.properties index 1d5d4d93..42123ee1 100644 --- a/src/main/resources/i18n/Tech_Gallery_en_US.properties +++ b/src/main/resources/i18n/Tech_Gallery_en_US.properties @@ -60,3 +60,5 @@ Link\ doesn't\ exist. = Link doesn't exist. Link\ or\ link's\ id\ cannot\ be\ null\ or\ blank. = Link or link's id cannot be null or blank. This\ link\ doesn't\ belong\ to\ this\ user. = This link doesn't belong to this user. This\ link\ is\ not\ valid. = This link is not valid. +Technology's\ category\ cannot\ be\ null\ or\ blank.=Technology's category cannot be null or blank. +Technology's\ category\ must\ be\ valid.\ Valid\ categories\:\ %s.\ %s\ given.=Technology's category must be valid. Valid categories: %s. %s given. diff --git a/src/test/java/com/ciandt/techgallery/service/TechnologyServiceTest.java b/src/test/java/com/ciandt/techgallery/service/TechnologyServiceTest.java index 44431b63..bb0fba02 100644 --- a/src/test/java/com/ciandt/techgallery/service/TechnologyServiceTest.java +++ b/src/test/java/com/ciandt/techgallery/service/TechnologyServiceTest.java @@ -1,6 +1,7 @@ package com.ciandt.techgallery.service; import com.ciandt.techgallery.persistence.model.Technology; +import com.ciandt.techgallery.service.enums.TechnologyCategoryEnum; import com.ciandt.techgallery.service.impl.TechnologyServiceImpl; import com.google.api.server.spi.response.BadRequestException; import com.google.appengine.api.users.User; @@ -27,6 +28,7 @@ public void shouldThrowBadRequestWhenInsertWithNoId() throws Exception { technology.setName("Angular JS"); technology.setDescription("Framework javascript"); technology.setShortDescription("Framework javascript"); + technology.setCategory(TechnologyCategoryEnum.FRAMEWORK.getId()); service.addOrUpdateTechnology(technology, currentUser); } @@ -37,6 +39,31 @@ public void shouldThrowBadRequestWhenInsertWithNoName() throws Exception { technology.setId(technology.convertNameToId("Angular JS")); technology.setDescription("Framework javascript"); technology.setShortDescription("Framework javascript"); + technology.setCategory(TechnologyCategoryEnum.FRAMEWORK.getId()); + + service.addOrUpdateTechnology(technology, currentUser); + } + + @Test (expected = BadRequestException.class) + public void shouldThrowBadRequestWhenInsertWithNoCategory() throws Exception { + Technology technology = new Technology(); + technology.setId(technology.convertNameToId("Angular JS")); + technology.setName("Angular JS"); + technology.setDescription("Framework javascript"); + technology.setShortDescription("Framework javascript"); + + service.addOrUpdateTechnology(technology, currentUser); + } + + + @Test (expected = BadRequestException.class) + public void shouldThrowBadRequestWhenInsertWithInvalidCategory() throws Exception { + Technology technology = new Technology(); + technology.setId(technology.convertNameToId("Angular JS")); + technology.setName("Angular JS"); + technology.setDescription("Framework javascript"); + technology.setShortDescription("Framework javascript"); + technology.setCategory("invalid-CATEGORY"); service.addOrUpdateTechnology(technology, currentUser); } diff --git a/src/test/java/service/technology/ShareTechnologyTest.java b/src/test/java/service/technology/ShareTechnologyTest.java index f4b8e93c..a75cf3d8 100644 --- a/src/test/java/service/technology/ShareTechnologyTest.java +++ b/src/test/java/service/technology/ShareTechnologyTest.java @@ -1,8 +1,13 @@ package service.technology; +import java.io.IOException; +import java.security.GeneralSecurityException; + import com.ciandt.techgallery.persistence.model.Technology; import com.ciandt.techgallery.service.TechnologyService; +import com.ciandt.techgallery.service.enums.TechnologyCategoryEnum; import com.ciandt.techgallery.service.impl.TechnologyServiceImpl; +import com.google.api.server.spi.response.BadRequestException; import com.google.appengine.api.users.User; import com.google.appengine.api.users.UserServiceFactory; import com.google.appengine.api.utils.SystemProperty; @@ -57,6 +62,7 @@ public void newDescriptionWhenTechnologyWasUpdated() throws Exception { technology.setName("Angular JS"); technology.setDescription("Framework javascript"); technology.setShortDescription("Framework javascript"); + technology.setCategory(TechnologyCategoryEnum.FRAMEWORK.getId()); Technology founded = service.addOrUpdateTechnology(technology, currentUser); @@ -83,6 +89,7 @@ public void addTechnologyWhenNotExists() throws Exception { technology.setName("Angular JS"); technology.setDescription("Framework javascript"); technology.setShortDescription("Framework javascript"); + technology.setCategory(TechnologyCategoryEnum.FRAMEWORK.getId()); // add imagem content - TODO: storage bucket not work using unit test // technology.setImageContent("sample base64 imagem data"); From 40ff99b96d5b21d0b6cb088d300c9af90b396168 Mon Sep 17 00:00:00 2001 From: Jean Pimentel Date: Thu, 3 Oct 2019 17:49:23 -0300 Subject: [PATCH 3/4] Adjust frontend --- .../service/endpoint/TechnologyEndpoint.java | 11 +++++++++++ .../controllers/TechnologyAddController.js | 16 ++++++++++++++-- .../technology/services/TechnologyService.js | 19 +++++++++++++++++-- .../technology/views/technology-add.html | 19 +++++++++++++++++-- .../webapp/app/modules/user/views/user.html | 2 +- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ciandt/techgallery/service/endpoint/TechnologyEndpoint.java b/src/main/java/com/ciandt/techgallery/service/endpoint/TechnologyEndpoint.java index 501a6160..b9cc305f 100644 --- a/src/main/java/com/ciandt/techgallery/service/endpoint/TechnologyEndpoint.java +++ b/src/main/java/com/ciandt/techgallery/service/endpoint/TechnologyEndpoint.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.util.List; +import java.util.Map; import java.util.logging.Logger; /** @@ -163,4 +164,14 @@ public Technology deleteTechnology(@Named("technologyId") String technologyId, U return service.deleteTechnology(technologyId, user); } + /** + * Endpoint for getting Technology categories. + * + * @return all categories + * @throws BadRequestException when some request parameter is wrong missing + */ + @ApiMethod(name = "getTechnologyCategories", path = "technology/categories", httpMethod = "get") + public Map getTechnologyCategories() throws BadRequestException{ + return service.getCategories(); + } } diff --git a/src/main/webapp/app/modules/technology/controllers/TechnologyAddController.js b/src/main/webapp/app/modules/technology/controllers/TechnologyAddController.js index aecb3ace..a595965d 100644 --- a/src/main/webapp/app/modules/technology/controllers/TechnologyAddController.js +++ b/src/main/webapp/app/modules/technology/controllers/TechnologyAddController.js @@ -37,7 +37,7 @@ module.exports = function ($rootScope, AppService, TechnologyService, ProjectSer context.project = {id: 0, name: 'Não'}; } - $scope.initSelect = function () { + $scope.initProjectsSelect = function () { ProjectService.getProjects().then(function (data) { if (!data) { data = []; @@ -47,13 +47,23 @@ module.exports = function ($rootScope, AppService, TechnologyService, ProjectSer }); }; + $scope.initCategoriesSelect = function () { + TechnologyService.getCategories().then(function (data) { + context.dropDownCategories = []; + for (var key in data) { + context.dropDownCategories.push({id: key, name: data[key]}); + } + }); + }; + + this.addOrUpdateTechnology = function (form) { if (context.project.id === 0) { context.project = undefined; } var isEdit = (context.id !== undefined); - if (context.name != null && context.description != null && context.shortDescription != null) { + if (context.name != null && context.description != null && context.shortDescription != null && context.category != null) { TechnologyService.addOrUpdate(context).then(function (data) { if (data.hasOwnProperty('error')) { AppService.setAlert(data.error.message, 'error'); @@ -84,6 +94,7 @@ module.exports = function ($rootScope, AppService, TechnologyService, ProjectSer context.description = ''; context.shortDescription = ''; context.webSite = ''; + context.category = ''; document.getElementById('technology-name').value = null; document.getElementById('technology-project').value = null; document.getElementById('list').innerHTML = [''].join(''); @@ -98,6 +109,7 @@ module.exports = function ($rootScope, AppService, TechnologyService, ProjectSer context.webSite = technology.website; context.image = technology.image; context.project = (technology.project ? technology.project : {id: 0, name: 'Não'}); + context.category = technology.category; if (context.image) { document.getElementById('list').innerHTML = [''].join(''); } diff --git a/src/main/webapp/app/modules/technology/services/TechnologyService.js b/src/main/webapp/app/modules/technology/services/TechnologyService.js index 11227a24..c2199e4a 100644 --- a/src/main/webapp/app/modules/technology/services/TechnologyService.js +++ b/src/main/webapp/app/modules/technology/services/TechnologyService.js @@ -87,7 +87,8 @@ module.exports = function($q, $timeout, $rootScope) { description : context.description, website : context.webSite, image : context.image, - project : context.project + project : context.project, + category : context.category.id }; return req; }else{ @@ -101,7 +102,8 @@ module.exports = function($q, $timeout, $rootScope) { description : context.description, website : context.webSite, imageContent : context.image, - project : context.project + project : context.project, + category : context.category.id }; return req; } @@ -467,4 +469,17 @@ module.exports = function($q, $timeout, $rootScope) { }); return deferred.promise; }; + + /** + * Retrieve list of categories + * @return {Promise} The gapi response + */ + this.getCategories = function () { + var deferred = $q.defer(); + gapi.client.rest.getTechnologyCategories().execute(function (data) { + context.foundItems = data.result; + deferred.resolve(context.foundItems); + }); + return deferred.promise; + }; }; diff --git a/src/main/webapp/app/modules/technology/views/technology-add.html b/src/main/webapp/app/modules/technology/views/technology-add.html index c022a2cd..a59084e6 100644 --- a/src/main/webapp/app/modules/technology/views/technology-add.html +++ b/src/main/webapp/app/modules/technology/views/technology-add.html @@ -51,11 +51,26 @@

Editar tecnologia

+ + +
+ + +
+ O campo Categoria é obrigatório +
+
+ + -
+
diff --git a/src/main/webapp/app/modules/user/views/user.html b/src/main/webapp/app/modules/user/views/user.html index c2860980..73a50729 100644 --- a/src/main/webapp/app/modules/user/views/user.html +++ b/src/main/webapp/app/modules/user/views/user.html @@ -41,7 +41,7 @@

{{ user.profile.owner.name }}

-
From cc3103f8c844e0cdc6ab864c547def31164c2232 Mon Sep 17 00:00:00 2001 From: Jean Pimentel Date: Sat, 5 Oct 2019 19:59:53 -0300 Subject: [PATCH 4/4] Fix bug where option wasn't selected when editing --- .../app/modules/technology/services/TechnologyService.js | 4 ++-- .../webapp/app/modules/technology/views/technology-add.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/webapp/app/modules/technology/services/TechnologyService.js b/src/main/webapp/app/modules/technology/services/TechnologyService.js index c2199e4a..064d16de 100644 --- a/src/main/webapp/app/modules/technology/services/TechnologyService.js +++ b/src/main/webapp/app/modules/technology/services/TechnologyService.js @@ -88,7 +88,7 @@ module.exports = function($q, $timeout, $rootScope) { website : context.webSite, image : context.image, project : context.project, - category : context.category.id + category : context.category }; return req; }else{ @@ -103,7 +103,7 @@ module.exports = function($q, $timeout, $rootScope) { website : context.webSite, imageContent : context.image, project : context.project, - category : context.category.id + category : context.category }; return req; } diff --git a/src/main/webapp/app/modules/technology/views/technology-add.html b/src/main/webapp/app/modules/technology/views/technology-add.html index a59084e6..0c5e9f90 100644 --- a/src/main/webapp/app/modules/technology/views/technology-add.html +++ b/src/main/webapp/app/modules/technology/views/technology-add.html @@ -58,7 +58,7 @@

Editar tecnologia

O campo Categoria é obrigatório