Skip to content

Commit

Permalink
SAS-766, SAS-735, SAS-731, SAS-673 merged feature branch into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaengel committed Sep 24, 2024
2 parents 1ac83de + 6931392 commit 4147f7e
Show file tree
Hide file tree
Showing 61 changed files with 4,043 additions and 3,649 deletions.
Binary file modified AI Bot Starter App.mpr
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AmazonBedrockClient {
private static final MxLogger LOGGER = new MxLogger(AmazonBedrockClient.class);

//TODO Replace X.Y.Z below with correct version nr and delete this line in rc-branch
private static final String AWS_HEADER_VALUE = "Mendix-Bedrock-5.2.0";
private static final String AWS_HEADER_VALUE = "Mendix-Bedrock-5.2.1";

public static BedrockClient getBedrockClient(Credentials credentials, ENUM_Region region, AbstractRequest request) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public IMendixObject executeAction() throws Exception
// Get Client Certificate from Environment variables
JSONObject cert = Utils.getClientCertificateDetails(ClientCertificateID);
if(nonNull(cert)) {
LOGGER.debug("Certificate found from Enviroment variables using ClientCertificate Id :: "+ClientCertificateID);
LOGGER.debug("Certificate found from Environment variables using ClientCertificate Id :: "+ClientCertificateID);
String pfxCert = cert.getString(PFX_KEY);
passPhrase = cert.getString(PASSWORD_KEY);
// Load certificate into stream
Expand All @@ -107,15 +107,15 @@ public IMendixObject executeAction() throws Exception
}
}else {
// Running locally form studio-pro, certificate from configuration.
LOGGER.debug("Certificate not found from Enviroment variables, searching in runtime configuration");
LOGGER.debug("Certificate not found from Environment variables, searching in runtime configuration");

int certIndex = getCertificateID();
// validates if the certificateID is not less than 0. As the input is 1 based but the retrieve is 0 based, the certIndex is check but the ClientCertificateID is logged
// Also, this check cannot be performed within the validation function, as the client certificate id can be any string in cloud environments
// TODO check if this can be moved to getCertificateID
if (certIndex < 0) {
LOGGER.error("The client certifcate id must be a number of 1 or greater. Instead value was set to: " + ClientCertificateID);
throw new IllegalArgumentException("The client certifcate id must be a number of 1 or greater. Instead value was set to: " + ClientCertificateID);
LOGGER.error("The client certificate id must be a number of 1 or greater. Instead value was set to: " + ClientCertificateID);
throw new IllegalArgumentException("The client certificate id must be a number of 1 or greater. Instead value was set to: " + ClientCertificateID);
}
LOGGER.debug("Searching certificate at index :: "+ClientCertificateID);
try(InputStream stream = Core.getConfiguration().getClientCertificates().get(certIndex)){
Expand Down Expand Up @@ -177,7 +177,7 @@ public IMendixObject executeAction() throws Exception
awsRegionString,
SERVICE);

// create the autherization header based on the steps found here: http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
// create the authorization header based on the steps found here: http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
String authorization_header = createAutherizationHeader(privateKey, algorithmName, algorithmHeader, amz_x509,
serial_number_dec, amzDate, requestParameters, signedHeaders, host, credentialScope);

Expand Down Expand Up @@ -303,7 +303,7 @@ private int getCertificateID() {
int certIndex = Integer.valueOf(ClientCertificateID) - ONE_TO_ZERO_INDEX_CORRECTION;
return certIndex;
} catch (NumberFormatException e) {
LOGGER.error("The client certifcate id must be a number of 1 or greater. Instead value was set to: " + ClientCertificateID);
LOGGER.error("The client certificate id must be a number of 1 or greater. Instead value was set to: " + ClientCertificateID);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AWSBuilderConfigurator<BuilderT extends AwsSyncClientBuilder<Builde
private static final MxLogger LOGGER = new MxLogger(AWSBuilderConfigurator.class);

//TODO Replace X.Y.Z below with correct version nr and delete this line in rc-branch
private static final String AWS_HEADER_VALUE = "Mendix-Authentication-3.1.2";
private static final String AWS_HEADER_VALUE = "Mendix-Authentication-3.1.3";

private AbstractRequest abstractRequest;
private ENUM_Region region;
Expand Down
130 changes: 65 additions & 65 deletions javasource/communitycommons/DateTime.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
package communitycommons;

import communitycommons.proxies.DatePartSelector;
import static communitycommons.proxies.DatePartSelector.day;
import static communitycommons.proxies.DatePartSelector.month;
import static communitycommons.proxies.DatePartSelector.year;
import java.util.Date;

import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Calendar;

public class DateTime {

/**
* @author mwe
* @author res
* @param firstDate The begin of the period
* @param compareDate The end of the period
* @return The period between the firstDate in the system default timezone, and the compareDate in the system
* default timezone as a Java Period
*
* Code is based on http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java
*
* Adjusted to Java 8 APIs (April, 2019)
*/
public static Period periodBetween(Date firstDate, Date compareDate) {
return Period.between(toLocalDate(firstDate), toLocalDate(compareDate));
}

private static LocalDate toLocalDate(Date someDate) {
return someDate.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}

public static long dateTimeToInteger(Date date, DatePartSelector selectorObj) {
Calendar newDate = Calendar.getInstance();
newDate.setTime(date);
int value = -1;
switch (selectorObj) {
case year:
value = newDate.get(Calendar.YEAR);
break;
case month:
value = newDate.get(Calendar.MONTH) + 1;
break; // Return starts at 0
case day:
value = newDate.get(Calendar.DAY_OF_MONTH);
break;
default:
break;
}
return value;
}

public static long dateTimeToLong(Date date) {
return date.getTime();
}

public static Date longToDateTime(Long value) {
return new Date(value);
}
}
package communitycommons;

import communitycommons.proxies.DatePartSelector;
import static communitycommons.proxies.DatePartSelector.day;
import static communitycommons.proxies.DatePartSelector.month;
import static communitycommons.proxies.DatePartSelector.year;
import java.util.Date;

import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Calendar;

public class DateTime {

/**
* @author mwe
* @author res
* @param firstDate The begin of the period
* @param compareDate The end of the period
* @return The period between the firstDate in the system default timezone, and the compareDate in the system
* default timezone as a Java Period
*
* Code is based on http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java
*
* Adjusted to Java 8 APIs (April, 2019)
*/
public static Period periodBetween(Date firstDate, Date compareDate) {
return Period.between(toLocalDate(firstDate), toLocalDate(compareDate));
}

private static LocalDate toLocalDate(Date someDate) {
return someDate.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}

public static long dateTimeToInteger(Date date, DatePartSelector selectorObj) {
Calendar newDate = Calendar.getInstance();
newDate.setTime(date);
int value = -1;
switch (selectorObj) {
case year:
value = newDate.get(Calendar.YEAR);
break;
case month:
value = newDate.get(Calendar.MONTH) + 1;
break; // Return starts at 0
case day:
value = newDate.get(Calendar.DAY_OF_MONTH);
break;
default:
break;
}
return value;
}

public static long dateTimeToLong(Date date) {
return date.getTime();
}

public static Date longToDateTime(Long value) {
return new Date(value);
}
}
116 changes: 58 additions & 58 deletions javasource/communitycommons/ImmutablePair.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package communitycommons;

import org.apache.commons.lang3.builder.HashCodeBuilder;


public class ImmutablePair<T, U>
{
public static <T, U> ImmutablePair<T, U> of(T left, U right) {
return new ImmutablePair<T, U>(left, right);
}

private final T left;
private final U right;

private ImmutablePair(T left, U right) {
if (left == null)
throw new IllegalArgumentException("Left is NULL");
if (right == null)
throw new IllegalArgumentException("Right is NULL");

this.left = left;
this.right = right;
}

public T getLeft() {
return left;
}

public U getRight() {
return right;
}

@Override
public String toString() {
return "<" + left.toString()+ "," + right.toString() + ">";
}

@Override
public boolean equals(Object other) {
if (!(other instanceof ImmutablePair<?,?>))
return false;

if (this == other)
return true;

ImmutablePair<?,?> o = (ImmutablePair<?, ?>) other;
return left.equals(o.getLeft()) && right.equals(o.getRight());
}

@Override
public int hashCode() {
return new HashCodeBuilder(19, 85)
.append(left)
.append(right)
.toHashCode();
}

}
package communitycommons;

import org.apache.commons.lang3.builder.HashCodeBuilder;


public class ImmutablePair<T, U>
{
public static <T, U> ImmutablePair<T, U> of(T left, U right) {
return new ImmutablePair<T, U>(left, right);
}

private final T left;
private final U right;

private ImmutablePair(T left, U right) {
if (left == null)
throw new IllegalArgumentException("Left is NULL");
if (right == null)
throw new IllegalArgumentException("Right is NULL");

this.left = left;
this.right = right;
}

public T getLeft() {
return left;
}

public U getRight() {
return right;
}

@Override
public String toString() {
return "<" + left.toString()+ "," + right.toString() + ">";
}

@Override
public boolean equals(Object other) {
if (!(other instanceof ImmutablePair<?,?>))
return false;

if (this == other)
return true;

ImmutablePair<?,?> o = (ImmutablePair<?, ?>) other;
return left.equals(o.getLeft()) && right.equals(o.getRight());
}

@Override
public int hashCode() {
return new HashCodeBuilder(19, 85)
.append(left)
.append(right)
.toHashCode();
}

}
Loading

0 comments on commit 4147f7e

Please sign in to comment.