Created
July 14, 2015 18:16
-
-
Save dardison/e384874634e3e13808bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Api(name = "productService", | |
scopes = {Constants.EMAIL_SCOPE}, | |
clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID, Constants.IOS_CLIENT_ID, | |
Constants.API_EXPLORER_CLIENT_ID}, | |
namespace = @ApiNamespace(ownerDomain = Constants.OWNER_DOMAIN, | |
ownerName = Constants.OWNER_DOMAIN, | |
packagePath="vbi.license.server.manager.model.license")) | |
public class ProductEndpoint extends BaseEndpoint<Product, ProductForm> { | |
public ProductEndpoint() { | |
super(Product.class, "Producto"); | |
} | |
@ApiMethod(name = "listProducts", path = "listProducts") | |
public List<ProductForm> listProducts(User user) throws UnauthorizedException { | |
if(user==null){ | |
throw new UnauthorizedException("No se encuentra logeado"); | |
} | |
return this.list("name"); | |
} | |
@ApiMethod(name = "getProduct", path = "getProduct") | |
public Product getProduct(@Named("id") Long id, User user) throws UnauthorizedException { | |
if(user==null){ | |
throw new UnauthorizedException("No se encuentra logeado"); | |
} | |
return this.getEntity(id).getEntity(); | |
} | |
@ApiMethod(name = "saveProduct") | |
public Product saveProduct(SaverProductRequestImpl request, User user) throws UnauthorizedException, NotFoundException, ValidationException{ | |
if(user==null){ | |
throw new UnauthorizedException("No se encuentra logeado"); | |
} | |
return this.saveEntity(request.getModel()); | |
} | |
@ApiMethod(name = "removeProduct") | |
public void removeProduct(@Named("id") Long id, User user) throws UnauthorizedException, NotFoundException { | |
if(user==null){ | |
throw new UnauthorizedException("No se encuentra logeado"); | |
} | |
this.removeEntity(id); | |
} | |
@Override | |
protected ProductForm buildFormFor(Product entity) { | |
ProductForm result=new ProductForm(); | |
result.setName(entity.getName()); | |
result.setReleaseDate(entity.getReleaseDate()); | |
result.setVersion(entity.getVersion()); | |
result.setActive(entity.isActive()); | |
return result; | |
} | |
@Override | |
protected Product buildEntity(ProductForm form) { | |
Product result=new Product(form); | |
return result; | |
} | |
@Override | |
protected Product updateEntity(Product entity, ProductForm form) throws ValidationException { | |
entity.setActive(form.getActive()); | |
entity.setName(form.getName()); | |
entity.setReleaseDate(form.getReleaseDate()); | |
entity.setVersion(form.getVersion()); | |
return entity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment