use of org.apache.ofbiz.service.group.GroupServiceModel in project ofbiz-framework by apache.
the class ModelService method interfaceUpdate.
/**
* Run the interface update and inherit all interface parameters
* @param dctx The DispatchContext to use for service lookups
*/
public synchronized void interfaceUpdate(DispatchContext dctx) throws GenericServiceException {
if (!inheritedParameters) {
// services w/ engine 'group' auto-implement the grouped services
if ("group".equals(this.engineName) && implServices.size() == 0) {
GroupModel group = internalGroup;
if (group == null) {
group = ServiceGroupReader.getGroupModel(this.location);
}
if (group != null) {
for (GroupServiceModel sm : group.getServices()) {
implServices.add(new ModelServiceIface(sm.getName(), sm.isOptional()));
if (Debug.verboseOn())
Debug.logVerbose("Adding service [" + sm.getName() + "] as interface of: [" + this.name + "]", module);
}
}
}
// handle interfaces
if (UtilValidate.isNotEmpty(implServices) && dctx != null) {
for (ModelServiceIface iface : implServices) {
String serviceName = iface.getService();
boolean optional = iface.isOptional();
ModelService model = dctx.getModelService(serviceName);
if (model != null) {
for (ModelParam newParam : model.contextParamList) {
ModelParam existingParam = this.contextInfo.get(newParam.name);
if (existingParam != null) {
// TODO: this is another case where having different optional/required settings for IN and OUT would be quite valuable...
if (!IN_OUT_PARAM.equals(existingParam.mode) && !existingParam.mode.equals(newParam.mode)) {
existingParam.mode = IN_OUT_PARAM;
if (existingParam.optional || newParam.optional) {
existingParam.optional = true;
}
}
} else {
ModelParam newParamClone = new ModelParam(newParam);
if (optional) {
// default option is to make this optional, however the service can override and
// force the clone to use the parents setting.
newParamClone.optional = true;
}
this.addParam(newParamClone);
}
}
} else {
Debug.logWarning("Inherited model [" + serviceName + "] not found for [" + this.name + "]", module);
}
}
}
// handle any override parameters
if (UtilValidate.isNotEmpty(overrideParameters)) {
for (ModelParam overrideParam : overrideParameters) {
ModelParam existingParam = contextInfo.get(overrideParam.name);
// keep the list clean, remove it then add it back
contextParamList.remove(existingParam);
if (existingParam != null) {
// now re-write the parameters
if (UtilValidate.isNotEmpty(overrideParam.type)) {
existingParam.type = overrideParam.type;
}
if (UtilValidate.isNotEmpty(overrideParam.mode)) {
existingParam.mode = overrideParam.mode;
}
if (UtilValidate.isNotEmpty(overrideParam.entityName)) {
existingParam.entityName = overrideParam.entityName;
}
if (UtilValidate.isNotEmpty(overrideParam.fieldName)) {
existingParam.fieldName = overrideParam.fieldName;
}
if (UtilValidate.isNotEmpty(overrideParam.formLabel)) {
existingParam.formLabel = overrideParam.formLabel;
}
if (overrideParam.getDefaultValue() != null) {
existingParam.copyDefaultValue(overrideParam);
}
if (overrideParam.overrideFormDisplay) {
existingParam.formDisplay = overrideParam.formDisplay;
}
if (overrideParam.overrideOptional) {
existingParam.optional = overrideParam.optional;
}
if (UtilValidate.isNotEmpty(overrideParam.allowHtml)) {
existingParam.allowHtml = overrideParam.allowHtml;
}
addParam(existingParam);
} else {
Debug.logWarning("Override param found but no parameter existing; ignoring: " + overrideParam.name, module);
}
}
}
// set the flag so we don't do this again
this.inheritedParameters = true;
}
}
use of org.apache.ofbiz.service.group.GroupServiceModel in project ofbiz-framework by apache.
the class ServiceArtifactInfo method populateCalledServices.
protected void populateCalledServices() throws GeneralException {
// populate servicesCalledByThisService and for each the reverse-associate cache in the aif
if ("simple".equals(this.modelService.engineName)) {
// we can do something with this!
SimpleMethod simpleMethodToCall = null;
try {
simpleMethodToCall = SimpleMethod.getSimpleMethod(this.modelService.location, this.modelService.invoke, null);
} catch (MiniLangException e) {
Debug.logWarning("Error getting Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "]: " + e.toString(), module);
}
if (simpleMethodToCall == null) {
Debug.logWarning("Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "] not found", module);
return;
}
ArtifactInfoContext aic = new ArtifactInfoContext();
simpleMethodToCall.gatherArtifactInfo(aic);
populateServicesFromNameSet(aic.getServiceNames());
} else if ("java".equals(this.modelService.engineName)) {
String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
if (fullClassPathAndFile != null) {
String javaFile = null;
try {
javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
} catch (FileNotFoundException e) {
Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
return;
} catch (IOException e) {
Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
return;
}
javaFile = UtilJavaParse.stripComments(javaFile);
int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
Set<String> allServiceNameSet = UtilJavaParse.findServiceCallsInBlock(methodBlockStart, methodBlockEnd, javaFile);
populateServicesFromNameSet(allServiceNameSet);
}
} else if ("group".equals(this.modelService.engineName)) {
Set<String> allServiceNameSet = new HashSet<String>();
GroupModel groupModel = modelService.internalGroup;
if (groupModel == null) {
groupModel = ServiceGroupReader.getGroupModel(this.modelService.location);
}
if (groupModel != null) {
List<GroupServiceModel> groupServiceModels = groupModel.getServices();
for (GroupServiceModel groupServiceModel : groupServiceModels) {
allServiceNameSet.add(groupServiceModel.getName());
}
}
populateServicesFromNameSet(allServiceNameSet);
}
}
Aggregations