use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl in project jain-slee.diameter by RestComm.
the class AvpUtilities method performPreAddOperations.
/**
* @param parent the Message/Grouped AVP where AVP will be added to, for validation purposes. if null, no validation is performed.
* @param avpCode
* @param vendorId
* @param set
* @throws AvpNotAllowedException
*/
private static void performPreAddOperations(Object parent, int avpCode, long vendorId, AvpSet set) throws AvpNotAllowedException {
if (!dictionary.isEnabled()) {
// no need to proceed any further.. no validation
return;
}
if (parent instanceof Message) {
Message msg = (Message) parent;
MessageRepresentation msgRep = dictionary.getMessage(msg.getCommandCode(), msg.getApplicationId(), msg.isRequest());
// if we don't know anything about this message, let's just move on..
if (msgRep == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to find message in dictionary, skipping validation. (Command Code: " + msg.getCommandCode() + ", Application-Id: " + msg.getApplicationId() + ")");
}
return;
}
if (!msgRep.isAllowed(avpCode, vendorId)) {
throw new AvpNotAllowedException("Avp defined by code: " + avpCode + ", vendorId: " + vendorId + " is not allowed in message - code: " + msg.getCommandCode() + ", appId: " + msg.getApplicationId() + ", isRequest: " + msg.isRequest(), avpCode, vendorId);
}
if (msgRep.isCountValidForMultiplicity(msg.getAvps(), avpCode, vendorId, 1)) {
// its ok.
return;
} else {
throw new AvpNotAllowedException("Avp not allowed, count exceeded.", avpCode, vendorId);
}
} else if (parent instanceof GroupedAvp) {
GroupedAvpImpl gAvp = (GroupedAvpImpl) parent;
org.jdiameter.api.validation.AvpRepresentation parentAvpRep = dictionary.getAvp(gAvp.getCode(), gAvp.getVendorId());
// if we don't know anything about this avp, let's just move on..
if (parentAvpRep == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to find parent AVP in dictionary, skipping validation. (AVP Code: " + gAvp.getCode() + ", Vendor-Id: " + gAvp.getVendorId() + ")");
}
return;
}
if (!parentAvpRep.isAllowed(avpCode, vendorId)) {
throw new AvpNotAllowedException("AVP with Code '" + avpCode + "' and Vendor-Id '" + vendorId + "' is not allowed as a child of AVP with Code '" + parentAvpRep.getCode() + "' and Vendor-Id '" + parentAvpRep.getVendorId() + "'.", avpCode, vendorId);
}
// Now we get the actual AVP to add representation...
org.jdiameter.api.validation.AvpRepresentation avpRep = dictionary.getAvp(avpCode, vendorId);
// ..to check if it can be added (multiplicity) to the parent.
if (avpRep.isCountValidForMultiplicity(gAvp.getGenericData(), 1)) {
// its ok.
return;
} else {
throw new AvpNotAllowedException("Avp not allowed, count exceeded.", avpCode, vendorId);
}
}
}
Aggregations