Skip to content

Commit

Permalink
Merge pull request #7145 from breakponchito/FISH-10228-fix-to-inject-…
Browse files Browse the repository at this point in the history
…resource-for-mdb-with-activation-config-property

FISH-10228: fixing issue to inject resource added from activation-config-property
  • Loading branch information
breakponchito authored Jan 6, 2025
2 parents 71b8d1b + 6234ca1 commit 4321897
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017-2021] Payara Foundation and/or affiliates
* Portions Copyright [2017-2025] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.deployment.annotation.handlers;
Expand All @@ -46,6 +46,8 @@
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.annotation.context.ResourceContainerContext;
import com.sun.enterprise.deployment.annotation.context.ResourceContainerContextImpl;
import java.util.Arrays;
import java.util.Optional;
import org.glassfish.apf.AnnotationHandlerFor;
import org.glassfish.apf.AnnotationInfo;
import org.glassfish.apf.AnnotationProcessorException;
Expand Down Expand Up @@ -241,6 +243,14 @@ protected HandlerProcessingResult processResource(AnnotationInfo ainfo,
// set it using the resource type of field/method
desc.setInjectResourceType(resourceType.getName());
}

//if value is empty we need to verify any other available descriptor that use same field with not empty value
if (!ok(desc.getValue())) {
String valueFound = searchValueIfAvailable(target.getFieldName(), descriptors);
if (!valueFound.isEmpty()) {
desc.setValue(valueFound);
}
}

// merge description
if (!ok(desc.getDescription()) && ok(resourceAn.description()))
Expand Down Expand Up @@ -291,6 +301,23 @@ protected HandlerProcessingResult processResource(AnnotationInfo ainfo,
return getDefaultProcessedResult();
}

/**
* Method to verify any other Environment Properties that contain same field name and return value if not empty
*
* @param fieldName field to search
* @param descriptors available descriptors for EJB
* @return String value
*/
private String searchValueIfAvailable(String fieldName, EnvironmentProperty[] descriptors) {
return Arrays.stream(descriptors)
.filter(d -> d.getDisplayName().equalsIgnoreCase(fieldName) ||
fieldName.toLowerCase().contains(d.getDisplayName().toLowerCase()))
.filter(EnvironmentProperty::hasAValue)
.findFirst()
.map(EnvironmentProperty::getValue)
.orElse("");
}

private EnvironmentProperty[] getDescriptors(Class resourceType,
String logicalName, ResourceContainerContext[] rcContexts, Resource resourceAn) {

Expand Down

0 comments on commit 4321897

Please sign in to comment.