Skip to content

Commit

Permalink
Added method to get the oms instnace url, in future we may have anoth…
Browse files Browse the repository at this point in the history
…er way to get the oms instnace url, will update the method to get the instnace url/
  • Loading branch information
dixitdeepak committed Mar 12, 2024
1 parent 24800ba commit 34bc098
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@

</out-parameters>
<actions>
<!-- TODO: Find better way to get the oms url-->
<entity-find-one entity-name="org.apache.ofbiz.common.property.SystemProperty" value-field="baseUrlProperty" cache="true">
<field-map field-name="systemResourceId" value="url"/>
<field-map field-name="systemPropertyId" value="content.url.prefix.secure"/>
</entity-find-one>
<script>
omsBaseUrl = co.hotwax.order.routing.OrderRoutingHelper.getOmsInstanceUrl(ec.ecfi);
token = co.hotwax.order.routing.OrderRoutingHelper.getOmsJwtToken(ec.ecfi);
</script>
<if condition="!token">
<return error="true" message="Unable to generate oms token, check JWT configuration"/>
</if>
<set field="omsBaseUrl" from="baseUrlProperty?.systemPropertyValue"/>
<if condition="!omsBaseUrl">
<return error="true" message="OMS base url not found"/>
</if>
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/co/hotwax/order/routing/OrderRoutingHelper.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package co.hotwax.order.routing;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;
import org.moqui.entity.EntityCondition;
import org.moqui.impl.context.ExecutionContextFactoryImpl;
import org.moqui.impl.entity.EntityConditionFactoryImpl;
import org.moqui.util.SystemBinding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.moqui.entity.EntityValue;

import javax.cache.Cache;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

public class OrderRoutingHelper {
protected static final Logger logger = LoggerFactory.getLogger(OrderRoutingHelper.class);
Expand Down Expand Up @@ -88,4 +81,19 @@ public static String getOmsJwtToken(ExecutionContextFactoryImpl ecfi) {
}
return null;
}
public static String getOmsInstanceUrl(ExecutionContextFactoryImpl ecfi) {
//TODO: For now just hardcode the SystemMessageRemote, need to find a better way to do this
EntityValue omsInstance = ecfi.entityFacade.find("moqui.service.message.SystemMessageRemote")
.condition("systemMessageRemoteId", "HC_OMS_CONFIG").useCache(true).disableAuthz().one();
if (omsInstance != null) {
return omsInstance.getString("sendUrl");
} else {
EntityValue omsInstanceProperty = ecfi.entityFacade.find("org.apache.ofbiz.common.property.SystemProperty")
.condition("systemResourceId", "url").condition("systemPropertyId" , "content.url.prefix.secure").useCache(true).disableAuthz().one();
if (omsInstanceProperty != null) {
return omsInstanceProperty.getString("systemPropertyValue");
}
}
return null;
}
}

0 comments on commit 34bc098

Please sign in to comment.