Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Technology extends BaseEntity<String> {
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 --------------------------------------------
Expand Down Expand Up @@ -112,6 +113,9 @@ public class Technology extends BaseEntity<String> {
@Ignore
private String imageContent;

@Index
private String category;

/*
* Getter's and Setter's --------------------------------------------
*/
Expand Down Expand Up @@ -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 --------------------------------------------
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.Map;

/**
* Services for Technologies.
Expand Down Expand Up @@ -102,12 +103,14 @@ 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 .
*/
Technology deleteTechnology(final String technologyId, User user)
throws InternalServerErrorException, BadRequestException, NotFoundException,
OAuthRequestException;

Map<String, String> getCategories();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<String, String> getTechnologyCategories() throws BadRequestException{
return service.getCategories();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<String, String> 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());
Expand Down Expand Up @@ -480,4 +497,13 @@ public Technology deleteTechnology(String technologyId, User user)
technologyDAO.update(technology);
return technology;
}

@Override
public Map<String, String> getCategories() {
Map<String, String> categories = new HashMap<>();
for (TechnologyCategoryEnum category : TechnologyCategoryEnum.values()) {
categories.put(category.getId(), category.getTitle());
}
return categories;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/i18n/Tech_Gallery_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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');
Expand Down Expand Up @@ -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 = ['<img src="/assets/images/no_image.png" title="Insira uma imagem" />'].join('');
Expand All @@ -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 = ['<img src="', context.image, '" title="', context.name, '" />'].join('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
return req;
}else{
Expand All @@ -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
};
return req;
}
Expand Down Expand Up @@ -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;
};
};
19 changes: 17 additions & 2 deletions src/main/webapp/app/modules/technology/views/technology-add.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,26 @@ <h1 class="card-title" ng-if="technology.id.length">Editar tecnologia</h1>
</div>
</div>
<!--End Technology Name-->

<!--Category Selector-->
<div class="form-group col-md-3"
ng-class="{'has-error': (addTechnologyForm.category.$invalid && addTechnologyForm.category.$touched) || (addTechnologyForm.$submitted && addTechnologyForm.category.$invalid)}">
<label for="technology-category">Categoria</label>
<select class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-model="technology.category"
id="technology-category" name="category" required="" ng-init="initCategoriesSelect()"
ng-options="category.id as category.name for category in technology.dropDownCategories">
</select>
<div ng-show="addTechnologyForm.$submitted || addTechnologyForm.category.$touched">
<span ng-show="addTechnologyForm.category.$error.required" class="help-block">O campo Categoria é obrigatório</span>
</div>
</div>
<!--End Category Selector-->

<!--Projects Selector-->
<div class="form-group col-md-7">
<div class="form-group col-md-4">
<label for="technology-project">Exibir apenas para projeto específico</label>
<select class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-model="technology.project"
id="technology-project" ng-init="initSelect()"
id="technology-project" ng-init="initProjectsSelect()"
ng-options="project.name for project in technology.dropDownProjects track by project.id">
</select>
<!--Project Modal-->
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/modules/user/views/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 class="user-name">{{ user.profile.owner.name }}</h1>
<!--Projects Selector-->
<div class="pull-right form-group col-md-5">
<label for="technology-project">Quer visualizar as tecnologias específicas de um projeto?</label>
<select class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-model="user.profile.owner.project" ng-init="initSelect()" ng-change="onProjectSelection()"
<select class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-model="user.profile.owner.project" ng-init="initProjectsSelect()" ng-change="onProjectSelection()"
ng-options="project.name for project in user.dropDownProjects track by project.id" id="technology-project">
</select>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading