Skip to content
Permalink
Browse files
JUDDI-922 fixed, note: API change
  • Loading branch information
spyhunter99 committed Jan 21, 2015
1 parent f7db6df commit 8c5350d8f7c554f4826096791f94aaed7b4ebf7f
Showing 25 changed files with 260 additions and 133 deletions.
@@ -124,12 +124,15 @@ public DispositionReport validateValues(ValidateValues body)
Set<String> validators = new HashSet<String>();
EntityManager em = PersistenceManager.getEntityManager();
EntityTransaction tx = em.getTransaction();
//for each key to process
try {
while (iterator.hasNext()) {

String key = iterator.next();
//find out if it needs to be validated
Tmodel find = em.find(org.apache.juddi.model.Tmodel.class, key);
if (find != null) {
//if it is, added it to the list
if (ContainsValidatedKey(find, UDDIConstants.IS_VALIDATED_BY)) {
validators.add(key);
}
@@ -158,6 +161,7 @@ public DispositionReport validateValues(ValidateValues body)
} else {
try {
vsv = (ValueSetValidator) Class.forName(clazz).newInstance();
logger.info("translated " + tmodelkey + " to class " + clazz);
vsv.validateValuesBindingTemplate(body.getBindingTemplate(), "");
vsv.validateValuesBusinessEntity(body.getBusinessEntity());
vsv.validateValuesBusinessService(body.getBusinessService(), "");
@@ -26,8 +26,6 @@
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
@@ -82,6 +82,7 @@ private static UDDIValueSetValidationPortType getPort(String url) throws ValueNo
{
log.warn("Unable to figure out how to use the URL " + url + " as a Value Set Validation Service transport mechanism.");
ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidurl", url));
throw x;
}

return vsv;
@@ -97,7 +98,8 @@ public static void ValidateTModel(String url, List<TModel> obj) throws ValueNotA
try {
DispositionReport validateValues = vsv.validateValues(req);
} catch (Exception ex) {
log.warn(ex);
log.warn(ex.getMessage());
log.debug(ex.getMessage(),ex);
ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
throw x;
}
@@ -111,7 +113,8 @@ public static void ValidateBinding(String url, List<BindingTemplate> obj) throws
try {
DispositionReport validateValues = vsv.validateValues(req);
} catch (Exception ex) {
log.warn(ex);
log.warn(ex.getMessage());
log.debug(ex.getMessage(),ex);
ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
throw x;
}
@@ -125,7 +128,8 @@ public static void ValidateService(String url, List<BusinessService> obj) throws
try {
DispositionReport validateValues = vsv.validateValues(req);
} catch (Exception ex) {
log.warn(ex);
log.warn(ex.getMessage());
log.debug(ex.getMessage(),ex);
ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
throw x;
}
@@ -140,7 +144,8 @@ public static void ValidateBusiness(String url, List<BusinessEntity> obj) throws
try {
DispositionReport validateValues = vsv.validateValues(req);
} catch (Exception ex) {
log.warn(ex);
log.warn(ex.getMessage());
log.debug(ex.getMessage(),ex);
ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
throw x;
}
@@ -153,7 +158,8 @@ public static void ValidatePubAss(String url, PublisherAssertion obj) throws Val
try {
DispositionReport validateValues = vsv.validateValues(req);
} catch (Exception ex) {
log.warn(ex);
log.warn(ex.getMessage());
log.debug(ex.getMessage(),ex);
ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
throw x;
}
@@ -30,14 +30,18 @@
import org.uddi.v3_service.DispositionReportFaultMessage;

/**
* A simple base class for the validator interface that lets you define a simple set of allowed values.
* All other values will be rejected. Valid values apply to all UDDI elements
* A simple base class for the validator interface that lets you define a simple
* set of allowed values. All other values will be rejected. Valid values apply
* to all UDDI elements
*
* @author Alex O'Ree
* @since 3.2.1
*
*
*/
public abstract class AbstractSimpleValidator implements ValueSetValidator {

public abstract String getMyKey();

@Override
public void validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
if (items == null) {
@@ -63,7 +67,7 @@ public void validateValuesBusinessEntity(List<BusinessEntity> items) throws Disp
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getCategoryBag() != null) {
validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), "businessEntity(" + i + ").categoryBag.");
validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), "businessEntity(" + i + ").categoryBag.");
validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), "businessEntity(" + i + ").categoryBagGroup.");
}
if (items.get(i).getIdentifierBag() != null) {
validatedValuesKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), "businessEntity(" + i + ").identifierBag.");
@@ -85,7 +89,7 @@ public void validateValuesBusinessService(List<BusinessService> items, String xp
validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), xpath + "businessService(" + i + ").categoryBag.");
}
if (items.get(i).getBindingTemplates() != null) {
validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").");
}
}
}
@@ -108,19 +112,25 @@ private void validatedValuesKeyRef(List<KeyedReference> items, String xpath) thr
if (items == null) {
return;
}
//StringBuilder badvalues=new StringBuilder();
String err = "";
for (int i = 0; i < items.size(); i++) {
List<String> validValues = getValidValues();
if (validValues != null) {
if (items.get(i).getTModelKey().equalsIgnoreCase(getMyKey())) {
List<String> validValues = getValidValues();
if (validValues != null) {
//ok we have some work to do
boolean valid = false;
for (int k = 0; k < validValues.size(); k++) {
if (validValues.get(k).equals(items.get(i).getKeyValue())) {
valid = true;
//boolean valid = false;
boolean localfound = false;
for (int k = 0; k < validValues.size(); k++) {
if (validValues.get(k).equals(items.get(i).getKeyValue())) {
// valid = true;
localfound = true;
}
}
if (!localfound) {
//badvalues.append(items.get(i).getKeyValue()).append(" ");
err += xpath + "keyedReference(" + i + ")=" + items.get(i).getKeyValue() + " ";
}
}
if (!valid) {
err += xpath + "keyedReference(" + i + ") ";
}
}
}
@@ -166,21 +176,17 @@ public static void validateKeyNotPresentKeyRef(List<KeyedReference> items, Strin
if (items == null) {
return;
}
String err = "";
for (int i = 0; i < items.size(); i++) {
validateKeyNotPresentKeyRef(items.get(i), key, itemtype);
}
if (err.length() > 0) {

}
}

public static void validateKeyNotPresentKeyRef(KeyedReference item, String key, String itemtype) throws DispositionReportFaultMessage {
if (item == null) {
return;
}
if (key.equalsIgnoreCase(item.getTModelKey())) {
throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "key " + key + " not allowed on " + itemtype) );
throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "key " + key + " not allowed on " + itemtype));
}
}

@@ -200,10 +206,11 @@ private String getPrintableValidValues() {
StringBuilder sb = new StringBuilder();
sb.append(" Valid Values:[");
List<String> validValues = getValidValues();
for (int i=0; i < validValues.size(); i++){
for (int i = 0; i < validValues.size(); i++) {
sb.append(validValues.get(i));
if (i+1< validValues.size())
if (i + 1 < validValues.size()) {
sb.append(",");
}
}
sb.append("]");
return sb.toString();

0 comments on commit 8c5350d

Please sign in to comment.