Newer
Older
package it.inaf.oats.ia2.tapschemamanager.webapp;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.SearchUCD;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.UCDInfo;
import it.inaf.oats.ia2.tapschemamanager.businesslayer.UCDServiceException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Sonia Zorba
committed
import javax.enterprise.context.Dependent;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
*/
Sonia Zorba
committed
@Dependent
public class SearchUCDDialog implements Serializable {
Sonia Zorba
committed
private static final long serialVersionUID = -3503024742241865133L;
private boolean manualInsertion;
private String UCDManualText;
private String description;
private boolean UCDnotFound;
private String UCDServiceErrorMessage;
private String selectedUCD;
private String suggestedUCD;
private List<UCDInfo> suggestedUCDs;
public SearchUCDDialog() {
suggestedUCDs = new ArrayList<UCDInfo>();
}
Sonia Zorba
committed
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isUCDnotFound() {
return UCDnotFound;
}
public String getSelectedUCD() {
return selectedUCD;
}
public String getSuggestedUCD() {
return suggestedUCD;
}
public List<UCDInfo> getSuggestedUCDs() {
return suggestedUCDs;
}
public void setDefault() {
UCDManualText = null;
description = null;
UCDnotFound = false;
selectedUCD = null;
suggestedUCD = null;
suggestedUCDs.clear();
UCDServiceErrorMessage = null;
public void search(String description) {
try {
setDefault();
this.description = description;
String assignResponse = SearchUCD.assign(description);
if (assignResponse == null) {
UCDnotFound = true;
} else {
selectedUCD = assignResponse;
suggestedUCD = assignResponse;
List<UCDInfo> suggestResponse = SearchUCD.suggest(description);
if (suggestResponse == null) {
UCDnotFound = true;
} else {
suggestedUCDs = suggestResponse;
} catch (UCDServiceException e) {
setUCDServiceErrorMessage(e);
Sonia Zorba
committed
public void selectUCD(String selectedUCD) {
this.selectedUCD = selectedUCD;
}
public void explain(UCDInfo ucdInfo) {
try {
SearchUCD.explain(ucdInfo);
} catch (UCDServiceException e) {
setUCDServiceErrorMessage(e);
}
}
public boolean isManualInsertion() {
return manualInsertion;
}
public void setManualInsertion(boolean manualInsertion) {
this.manualInsertion = manualInsertion;
}
public String getUCDServiceErrorMessage() {
return UCDServiceErrorMessage;
}
private void setUCDServiceErrorMessage(UCDServiceException e) {
setDefault();
UCDServiceErrorMessage = e.getMessage();
}
public String getUCDManualText() {
return UCDManualText;
}
public void setUCDManualText(String UCDManualText) {
this.UCDManualText = UCDManualText;
}
public void validateManualUCD(FacesContext context, UIComponent inputComponent, Object value) {
String textValue = (String) value;
String validatorMessage = null;
if (textValue == null || textValue.isEmpty()) {
validatorMessage = "UCD can't be null";
} else {
try {
if (!SearchUCD.validateManualUCD(textValue)) {
validatorMessage = "Invalid UCD!";
}
} catch (UCDServiceException e) {
setUCDServiceErrorMessage(e);
FacesContext.getCurrentInstance().validationFailed();
}
if (validatorMessage != null) {
throw new ValidatorException(new FacesMessage(validatorMessage));
}
}
public String getUCDRegExp() {
return SearchUCD.REG_EXP_UCD;
}
public String getNamespaceRegExp() {
return SearchUCD.REG_EXP_START_WITH_NAMESPACE;