use of com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup in project phoss-smp by phax.
the class SMPServiceGroupManagerJDBC method createSMPServiceGroup.
@Nonnull
public SMPServiceGroup createSMPServiceGroup(@Nonnull @Nonempty final String sOwnerID, @Nonnull final IParticipantIdentifier aParticipantID, @Nullable final String sExtension, final boolean bCreateInSML) throws SMPServerException {
ValueEnforcer.notEmpty(sOwnerID, "OwnerID");
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
if (LOGGER.isDebugEnabled())
LOGGER.debug("createSMPServiceGroup (" + sOwnerID + ", " + aParticipantID.getURIEncoded() + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ", " + bCreateInSML + ")");
final MutableBoolean aCreatedSGHook = new MutableBoolean(false);
final MutableBoolean aCreatedSGDB = new MutableBoolean(false);
final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
final Wrapper<Exception> aCaughtException = new Wrapper<>();
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Check if the passed service group ID is already in use
final SMPServiceGroup aDBServiceGroup = getSMPServiceGroupOfID(aParticipantID);
if (aDBServiceGroup != null)
throw new IllegalStateException("The service group with ID " + aParticipantID.getURIEncoded() + " already exists!");
if (bCreateInSML) {
// It's a new service group - Create in SML and remember that
// Throws exception in case of an error
aHook.createServiceGroup(aParticipantID);
aCreatedSGHook.set(true);
}
// Did not exist. Create it.
if (aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_service_group (businessIdentifierScheme, businessIdentifier, extension) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), sExtension)) > 0) {
aCreatedSGDB.set(true);
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_ownership (businessIdentifierScheme, businessIdentifier, username) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), sOwnerID));
}
}, aCaughtException::set);
if (aCreatedSGHook.booleanValue() && !aCreatedSGDB.booleanValue()) {
// Undo creation in SML again
try {
aHook.undoCreateServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex) {
LOGGER.error("Failed to undoCreateServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex);
}
}
if (eSuccess.isFailure() || aCaughtException.isSet() || !aCreatedSGDB.booleanValue()) {
AuditHelper.onAuditCreateFailure(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), sOwnerID, sExtension, Boolean.valueOf(bCreateInSML));
// Propagate contained exception
final Exception ex = aCaughtException.get();
if (ex instanceof SMPServerException)
throw (SMPServerException) ex;
if (ex instanceof RegistrationHookException)
throw new SMPSMLException("Failed to create '" + aParticipantID.getURIEncoded() + "' in SML", ex);
throw new SMPInternalErrorException("Error creating ServiceGroup '" + aParticipantID.getURIEncoded() + "'", ex);
}
if (LOGGER.isDebugEnabled())
LOGGER.debug("createSMPServiceGroup succeeded");
AuditHelper.onAuditCreateSuccess(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), sOwnerID, sExtension, Boolean.valueOf(bCreateInSML));
final SMPServiceGroup aServiceGroup = new SMPServiceGroup(sOwnerID, aParticipantID, sExtension);
if (m_aCache != null)
m_aCache.put(aParticipantID.getURIEncoded(), aServiceGroup);
m_aCBs.forEach(x -> x.onSMPServiceGroupCreated(aServiceGroup, bCreateInSML));
return aServiceGroup;
}
use of com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup in project phoss-smp by phax.
the class SMPServiceGroupManagerJDBC method getAllSMPServiceGroups.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceGroup> getAllSMPServiceGroups() {
if (LOGGER.isDebugEnabled())
LOGGER.debug("getAllSMPServiceGroups()");
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT sg.businessIdentifierScheme, sg.businessIdentifier, sg.extension, so.username" + " FROM smp_service_group sg, smp_ownership so" + " WHERE so.businessIdentifierScheme=sg.businessIdentifierScheme AND so.businessIdentifier=sg.businessIdentifier");
final ICommonsList<ISMPServiceGroup> ret = new CommonsArrayList<>();
if (aDBResult != null)
for (final DBResultRow aRow : aDBResult) ret.add(new SMPServiceGroup(aRow.getAsString(3), new SimpleParticipantIdentifier(aRow.getAsString(0), aRow.getAsString(1)), aRow.getAsString(2)));
return ret;
}
use of com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup in project phoss-smp by phax.
the class SMPServiceGroupManagerMongoDB method toDomain.
@Nonnull
@ReturnsMutableCopy
public static SMPServiceGroup toDomain(@Nonnull final Document aDoc) {
final String sOwnerID = aDoc.getString(BSON_OWNER_ID);
final IParticipantIdentifier aParticipantIdentifier = toParticipantID(aDoc.get(BSON_PARTICIPANT_ID, Document.class));
final String sExtension = aDoc.getString(BSON_EXTENSION);
return new SMPServiceGroup(sOwnerID, aParticipantIdentifier, sExtension);
}
use of com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup in project phoss-smp by phax.
the class SMPServiceGroupManagerXML method updateSMPServiceGroup.
@Nonnull
public EChange updateSMPServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull @Nonempty final String sNewOwnerID, @Nullable final String sExtension) throws SMPServerException {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notEmpty(sNewOwnerID, "NewOwnerID");
if (LOGGER.isDebugEnabled())
LOGGER.debug("updateSMPServiceGroup (" + aParticipantID.getURIEncoded() + ", " + sNewOwnerID + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ")");
final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
final SMPServiceGroup aSMPServiceGroup = getOfID(sServiceGroupID);
if (aSMPServiceGroup == null) {
AuditHelper.onAuditModifyFailure(SMPServiceGroup.OT, "set-all", sServiceGroupID, "no-such-id");
if (LOGGER.isDebugEnabled())
LOGGER.debug("updateSMPServiceGroup - failure");
throw new SMPNotFoundException("No such service group '" + sServiceGroupID + "'");
}
m_aRWLock.writeLock().lock();
try {
EChange eChange = EChange.UNCHANGED;
eChange = eChange.or(aSMPServiceGroup.setOwnerID(sNewOwnerID));
eChange = eChange.or(aSMPServiceGroup.setExtensionAsString(sExtension));
if (eChange.isUnchanged()) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("updateSMPServiceGroup - unchanged");
return EChange.UNCHANGED;
}
internalUpdateItem(aSMPServiceGroup);
} finally {
m_aRWLock.writeLock().unlock();
}
AuditHelper.onAuditModifySuccess(SMPServiceGroup.OT, "set-all", sServiceGroupID, sNewOwnerID, sExtension);
if (LOGGER.isDebugEnabled())
LOGGER.debug("updateSMPServiceGroup - success");
m_aCBs.forEach(x -> x.onSMPServiceGroupUpdated(aParticipantID));
return EChange.CHANGED;
}
use of com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup in project phoss-smp by phax.
the class SMPRedirectTest method testCaseSensitivity.
@Test
public void testCaseSensitivity() {
final IParticipantIdentifier aPI = new SimpleParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:UpperCase");
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testDocType");
final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
// Create new one
final ISMPRedirect aRedirect = new SMPRedirect(aSG, aDocTypeID, "target", "suid", null, "<extredirect/>");
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("target", aRedirect.getTargetHref());
assertEquals("suid", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertFalse(aRedirect.hasCertificate());
assertEquals("[{\"Any\":\"<extredirect />\"}]", aRedirect.getExtensionsAsString());
}
Aggregations