Skip to content

Instantly share code, notes, and snippets.

View emoran's full-sized avatar
:octocat:
Developing

Edgar Moran emoran

:octocat:
Developing
View GitHub Profile
@emoran
emoran / Walmart.cls
Created March 10, 2022 16:04
Sample apex code to make a request to Walmart API service and generate the signature for the WM_SEC.AUTH_SIGNATURE header from Salesforce
/**
* Edgar Moran
* March 2022
*/
public with sharing class Walmart {
@InvocableMethod(label='Send Message')
public static List<String> sendMessage(List<String> message) {
String consumerId ='CONSUMER_ID';
@emoran
emoran / WalmartHeaderSignature.java
Created March 10, 2022 11:58
Walmart Header Signature snippet. Allows to generate the WM_SEC.AUTH_SIGNATURE header to authenticate in Walmart API services.
import org.apache.commons.codec.binary.Base64;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
public class WalmartHeaderSignature {
private static String consumerId = "CONSUMER_ID"; // Trimmed for security reason
private static String baseUrl = "URL";
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.emoran</groupId>
<artifactId>yucelmoran-azure-pipeline</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>yucelmoran-azure-pipeline</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>yucelmoran-azure-pipeline</id>
<username>yucelmorans</username>
<!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. -->
<!-- The generated token expires on or before 17/11/2019 -->
<password>${azure.password}</password>
</server>
%dw 2.0
import try, fail from dw::Runtime
output application/java
fun isDate(value: Any): Boolean = try(() -> value as Date).success
fun getDate(value: Any): Date | Null | Any = ( if ( isDate(value) ) value
as Date as String else value )
---
(payload.fields filter ($."type" != "LOCATION") map {
fieldName : $.name
}).fieldName joinBy ","
%dw 2.0
input payload application/java
output application/java
fun validateField(field) = if ( (field == "REFERENCE")
or (field == "ID") or
(field == "PICKLIST") or
(field == "TEXTAREA") or
(field == "ADDRESS")or
(field == "EMAIL")or
(field == "PHONE") or
payload.sobjects filter ( $.queryable == true and
$.replicateable == true and
$.retrieveable == true and
$.searchable == true and
$.triggerable == true and
($.name == "Account" or
$.name == "Contact" or
$.name =="Project__c")) map $
@emoran
emoran / dynamicFieldsDateValidation
Created February 10, 2022 14:33
Dataweave 2.0 Script that allows to set dynamically fields from a payload and set the date format for strings that are date / datetime
%dw 2.0
import try, fail from dw::Runtime
output application/java
fun isDate(value: Any): Boolean = try(() -> value as Date).success
fun getDate(value: Any): Date | Null | Any = ( if ( isDate(value) ) value
as Date as String else value )
---
@emoran
emoran / scatterGatherDW2.txt
Last active October 21, 2022 19:19
combine scatter gather result Mule 4
%dw 2.0
output application/json
---
flatten (dw::core::Objects::entrySet (payload) map ($[1].payload))