Services

Crear los services:

  • BodegaServices

  • ColorServices

  • PaisServices

BodegaServices

import com.avbravo.avbravoutils.JsfUtil;
import com.avbravo.microtestingejb.entity.Bodega;
import com.avbravo.microtestingejb.repository.BodegaRepository;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import org.bson.Document;
/**
*
* @authoravbravo
*/
@Stateless
public class BodegaServices {
@Inject
BodegaRepository bodegaRepository;
public List<Bodega> complete(String query) {
List<Bodega> suggestions = new ArrayList<>();
try {
query = query.trim();
if (query.length() < 1) {
return suggestions;
}
String field = (String) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("field");
suggestions= bodegaRepository.findRegex(field,query,true,new Document(field,1));
} catch (Exception e) {
JsfUtil.errorMessage("complete() " + e.getLocalizedMessage());
}
return suggestions;
}
}

ColorServices

import com.avbravo.avbravoutils.JsfUtil;
import com.avbravo.microtestingejb.entity.Color;
import com.avbravo.microtestingejb.repository.ColorRepository;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import org.bson.Document;
/**
*
* @authoravbravo
*/
@Stateless
public class ColorServices {
@Inject
ColorRepository colorRepository;
public List<Color> complete(String query) {
List<Color> suggestions = new ArrayList<>();
try {
query = query.trim();
if (query.length() < 1) {
return suggestions;
}
String field = (String) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("field");
suggestions= colorRepository.findRegex(field,query,true,new Document(field,1));
} catch (Exception e) {
JsfUtil.errorMessage("complete() " + e.getLocalizedMessage());
}
return suggestions;
}
}

PaisServices

import com.avbravo.avbravoutils.JsfUtil;
import com.avbravo.microtestingejb.entity.Pais;
import com.avbravo.microtestingejb.repository.PaisRepository;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import org.bson.Document;
/**
*
* @authoravbravo
*/
@Stateless
public class PaisServices {
@Inject
PaisRepository paisRepository;
public List<Pais> complete(String query) {
List<Pais> suggestions = new ArrayList<>();
try {
String field = (String) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("field");
query = query.trim();
if (query.length() < 1) {
return suggestions;
}
suggestions= paisRepository.findRegex(field, query,true,new Document(field,1));
} catch (Exception e) {
JsfUtil.errorMessage("complete() " + e.getLocalizedMessage());
}
return suggestions;
}
}