Search in sources :

Example 1 with SMPParticipantMigration

use of com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration in project phoss-smp by phax.

the class SMPParticipantMigrationManagerJDBC method getParticipantMigrationOfID.

@Nullable
public SMPParticipantMigration getParticipantMigrationOfID(@Nullable final String sID) {
    if (StringHelper.hasNoText(sID))
        return null;
    final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
    newExecutor().querySingle("SELECT direction, state, pid, initdt, migkey FROM smp_pmigration WHERE id=?", new ConstantPreparedStatementDataProvider(sID), aDBResult::set);
    if (aDBResult.isNotSet())
        return null;
    final DBResultRow aRow = aDBResult.get();
    final EParticipantMigrationDirection eDirection = EParticipantMigrationDirection.getFromIDOrNull(aRow.getAsString(0));
    final EParticipantMigrationState eState = EParticipantMigrationState.getFromIDOrNull(aRow.getAsString(1));
    final IParticipantIdentifier aPI = SMPMetaManager.getIdentifierFactory().parseParticipantIdentifier(aRow.getAsString(2));
    return new SMPParticipantMigration(sID, eDirection, eState, aPI, aRow.getAsLocalDateTime(3), aRow.getAsString(4));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) EParticipantMigrationDirection(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationDirection) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nullable(javax.annotation.Nullable)

Example 2 with SMPParticipantMigration

use of com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration in project phoss-smp by phax.

the class SMPParticipantMigrationManagerMongoDB method createInboundParticipantMigration.

@Nonnull
public ISMPParticipantMigration createInboundParticipantMigration(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull @Nonempty final String sMigrationKey) {
    final SMPParticipantMigration aSMPParticipantMigration = SMPParticipantMigration.createInbound(aParticipantID, sMigrationKey);
    _createParticipantMigration(aSMPParticipantMigration);
    return aSMPParticipantMigration;
}
Also used : SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) Nonnull(javax.annotation.Nonnull)

Example 3 with SMPParticipantMigration

use of com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration in project phoss-smp by phax.

the class SMPParticipantMigrationManagerMongoDB method toDomain.

@Nonnull
@ReturnsMutableCopy
public static SMPParticipantMigration toDomain(@Nonnull final Document aDoc) {
    final String sID = aDoc.getString(BSON_ID);
    final EParticipantMigrationDirection eDirection = EParticipantMigrationDirection.getFromIDOrNull(aDoc.getString(BSON_DIRECTION));
    final EParticipantMigrationState eState = EParticipantMigrationState.getFromIDOrNull(aDoc.getString(BSON_STATE));
    final IParticipantIdentifier aParticipantID = toParticipantID(aDoc.get(BSON_PARTICIPANT_ID, Document.class));
    final LocalDateTime aInitiationDateTime = TypeConverter.convert(aDoc.getDate(BSON_INIT_DT), LocalDateTime.class);
    final String sMigrationKey = aDoc.getString(BSON_MIGRATION_KEY);
    return new SMPParticipantMigration(sID, eDirection, eState, aParticipantID, aInitiationDateTime, sMigrationKey);
}
Also used : LocalDateTime(java.time.LocalDateTime) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) Document(org.bson.Document) EParticipantMigrationDirection(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationDirection) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 4 with SMPParticipantMigration

use of com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration in project phoss-smp by phax.

the class SMPParticipantMigrationManagerMongoDB method setParticipantMigrationState.

@Nonnull
public EChange setParticipantMigrationState(@Nullable final String sParticipantMigrationID, @Nonnull final EParticipantMigrationState eNewState) {
    ValueEnforcer.notNull(eNewState, "NewState");
    final SMPParticipantMigration aPM = getParticipantMigrationOfID(sParticipantMigrationID);
    if (aPM == null) {
        AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, "no-such-id");
        return EChange.UNCHANGED;
    }
    {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aPM.setState(eNewState));
        if (eChange.isUnchanged())
            return EChange.UNCHANGED;
        getCollection().findOneAndReplace(new Document(BSON_ID, sParticipantMigrationID), toBson(aPM));
    }
    AuditHelper.onAuditModifySuccess(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState);
    return EChange.CHANGED;
}
Also used : SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) EChange(com.helger.commons.state.EChange) Document(org.bson.Document) Nonnull(javax.annotation.Nonnull)

Example 5 with SMPParticipantMigration

use of com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration in project phoss-smp by phax.

the class SMPParticipantMigrationManagerJDBC method getParticipantMigrationOfParticipantID.

@Nullable
public ISMPParticipantMigration getParticipantMigrationOfParticipantID(@Nonnull final EParticipantMigrationDirection eDirection, @Nonnull final EParticipantMigrationState eState, @Nullable final IParticipantIdentifier aParticipantID) {
    ValueEnforcer.notNull(eDirection, "Direction");
    ValueEnforcer.notNull(eState, "State");
    if (aParticipantID == null)
        return null;
    final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
    newExecutor().querySingle("SELECT id, initdt, migkey FROM smp_pmigration WHERE direction=? AND state=? AND pid=?", new ConstantPreparedStatementDataProvider(eDirection.getID(), eState.getID(), aParticipantID.getURIEncoded()), aDBResult::set);
    if (aDBResult.isNotSet())
        return null;
    final DBResultRow aRow = aDBResult.get();
    return new SMPParticipantMigration(aRow.getAsString(0), eDirection, eState, aParticipantID, aRow.getAsLocalDateTime(1), aRow.getAsString(2));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nullable(javax.annotation.Nullable)

Aggregations

SMPParticipantMigration (com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration)7 ISMPParticipantMigration (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration)6 Nonnull (javax.annotation.Nonnull)4 Document (org.bson.Document)3 Wrapper (com.helger.commons.wrapper.Wrapper)2 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)2 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)2 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 EParticipantMigrationDirection (com.helger.phoss.smp.domain.pmigration.EParticipantMigrationDirection)2 EParticipantMigrationState (com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState)2 Nullable (javax.annotation.Nullable)2 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)1 EChange (com.helger.commons.state.EChange)1 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)1 LocalDateTime (java.time.LocalDateTime)1 Test (org.junit.Test)1