Skip to content

Commit

Permalink
Extended internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Mar 19, 2024
1 parent dab2e2a commit d4a7be5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.helger.phive.api.executorset;

import java.time.OffsetDateTime;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -28,6 +30,22 @@ default boolean isDeprecated ()
return getType ().isDeprecated ();
}

default boolean hasValidFrom ()
{
return getValidFrom () != null;
}

@Nullable
OffsetDateTime getValidFrom ();

default boolean hasValidTo ()
{
return getValidTo () != null;
}

@Nullable
OffsetDateTime getValidTo ();

/**
* @return <code>true</code> if a replacement VESID is present,
* <code>false</code> if not.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.helger.phive.api.executorset;

import java.time.OffsetDateTime;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand All @@ -16,22 +18,40 @@
public class ValidationExecutorSetStatus implements IValidationExecutorSetStatus
{
private final EValidationExecutorStatusType m_eType;
private final OffsetDateTime m_aValidFrom;
private final OffsetDateTime m_aValidTo;
private final VESID m_aReplacementVESID;

public ValidationExecutorSetStatus (@Nonnull final EValidationExecutorStatusType eType,
@Nullable final OffsetDateTime aValidFrom,
@Nullable final OffsetDateTime aValidTo,
@Nullable final VESID aReplacementVESID)
{
ValueEnforcer.notNull (eType, "Type");
m_eType = eType;
m_aValidFrom = aValidFrom;
m_aValidTo = aValidTo;
m_aReplacementVESID = aReplacementVESID;
}

@Nonnull
public EValidationExecutorStatusType getType ()
public final EValidationExecutorStatusType getType ()
{
return m_eType;
}

@Nullable
public final OffsetDateTime getValidFrom ()
{
return m_aValidFrom;
}

@Nullable
public final OffsetDateTime getValidTo ()
{
return m_aValidTo;
}

@Nullable
public VESID getReplacementVESID ()
{
Expand All @@ -42,20 +62,22 @@ public VESID getReplacementVESID ()
public String toString ()
{
return new ToStringGenerator (null).append ("Type", m_eType)
.append ("ValidFrom", m_aValidFrom)
.append ("ValidTo", m_aValidTo)
.append ("ReplacementVESID", m_aReplacementVESID)
.getToString ();
}

@Nonnull
public static ValidationExecutorSetStatus createValid ()
{
return new ValidationExecutorSetStatus (EValidationExecutorStatusType.VALID, null);
return createDeprecated (false);
}

@Nonnull
public static ValidationExecutorSetStatus createDeprecated (final boolean bDeprecated)
{
return new ValidationExecutorSetStatus (bDeprecated ? EValidationExecutorStatusType.DEPRECATED
: EValidationExecutorStatusType.VALID, null);
: EValidationExecutorStatusType.VALID, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testValidationResults ()
ValidationExecutorSetStatus.createValid ());
PhiveJsonHelper.applyValidationResultList (aObj, aVES, new CommonsArrayList <> (), aDisplayLocale, 123, null, null);
final String sJson = aObj.getAsJsonString ();
assertEquals ("{\"ves\":{\"vesid\":\"group:art:1\",\"name\":\"name\",\"deprecated\":false}," +
assertEquals ("{\"ves\":{\"vesid\":\"group:art:1\",\"name\":\"name\",\"deprecated\":false,\"status\":{\"type\":\"valid\"}}," +
"\"success\":true," +
"\"interrupted\":false," +
"\"mostSevereErrorLevel\":\"SUCCESS\"," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.helger.phive.ves.engine.load;

import java.time.OffsetDateTime;
import java.util.Locale;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -143,6 +144,30 @@ public XMLOffsetDateTime getStatusLastModification ()
return m_aStatusLastMod;
}

@Nonnull
public XMLOffsetDateTime getValidFrom ()
{
return m_aValidFrom;
}

@Nonnull
public OffsetDateTime getValidFromOffset ()
{
return m_aValidFrom == null ? null : m_aValidFrom.toOffsetDateTime ();
}

@Nonnull
public XMLOffsetDateTime getValidTo ()
{
return m_aValidTo;
}

@Nonnull
public OffsetDateTime getValidToOffset ()
{
return m_aValidTo == null ? null : m_aValidTo.toOffsetDateTime ();
}

@Nonnull
public EValidationExecutorStatusType getDateTimeValidityNow ()
{
Expand Down Expand Up @@ -429,13 +454,16 @@ public void applyValidation (@Nonnull final IValidationSource aValidationSource,
if (!hasExecutor ())
throw new VESLoadingException ("The loaded VES has no Executor Set and can therefore not be used for validating objects");

final EValidationExecutorStatusType eStatus = _getRecursiveExecutorStatusType ();
final EValidationExecutorStatusType eStatusType = _getRecursiveExecutorStatusType ();
final ICommonsList <IValidationExecutor <IValidationSource>> aExecutors = _getValidationExecutorsRecursive ();

final ValidationExecutorSetStatus aVESStatus = new ValidationExecutorSetStatus (eStatusType,
m_aStatus.getValidFromOffset (),
m_aStatus.getValidToOffset (),
m_aStatus.getReplacementVESID ());
final IValidationExecutorSet <IValidationSource> aVES = ValidationExecutorSet.create (m_aHeader.getVESID (),
m_aHeader.getName (),
new ValidationExecutorSetStatus (eStatus,
m_aStatus.getReplacementVESID ()),
aVESStatus,
aExecutors);

// Validate
Expand Down

0 comments on commit d4a7be5

Please sign in to comment.