use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class BusinessCardServerAPI method getBusinessCard.
@Nonnull
public PD3BusinessCardType getBusinessCard(final String sServiceGroupID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /businesscard/" + sServiceGroupID;
final String sAction = "getBusinessCard";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
}
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr == null) {
throw new SMPBadRequestException("This SMP server does not support the Business Card API", m_aAPIProvider.getCurrentURI());
}
final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aServiceGroup);
if (aBusinessCard == null) {
// No such business card
throw new SMPNotFoundException("No Business Card assigned to Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aBusinessCard.getAsJAXBObject();
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class SMPServerAPI method saveServiceGroup.
public void saveServiceGroup(@Nonnull final String sPathServiceGroupID, @Nonnull final ServiceGroupType aServiceGroup, final boolean bCreateInSML, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + (bCreateInSML ? "" : CSMPServer.LOG_SUFFIX_NO_SML_INTERACTION);
final String sAction = "saveServiceGroup";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " ==> " + aServiceGroup);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
// Parse the content of the payload with the same identifier factory to
// ensure same case sensitivity
final IParticipantIdentifier aPayloadServiceGroupID;
if (aServiceGroup.getParticipantIdentifier() == null) {
// Can happen when tampering with the input data
aPayloadServiceGroupID = null;
} else {
aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceGroup.getParticipantIdentifier().getScheme(), aServiceGroup.getParticipantIdentifier().getValue());
}
if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
// Business identifiers must be equal
throw new SMPBadRequestException("Service Group Inconsistency. The URL points to '" + aPathServiceGroupID.getURIEncoded() + "' whereas the Service Group contains " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'"), m_aAPIDataProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final String sExtension = SMPExtensionConverter.convertToString(aServiceGroup.getExtension());
if (aServiceGroupMgr.containsSMPServiceGroupWithID(aPathServiceGroupID))
aServiceGroupMgr.updateSMPServiceGroup(aPathServiceGroupID, aSMPUser.getID(), sExtension);
else
aServiceGroupMgr.createSMPServiceGroup(aSMPUser.getID(), aPathServiceGroupID, sExtension, bCreateInSML);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class SMPServerAPI method deleteServiceRegistration.
public void deleteServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
final String sAction = "deleteServiceRegistration";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
if (aPathDocTypeID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
if (aServiceInfo != null) {
// Handle service information
final EChange eChange = aServiceInfoMgr.deleteSMPServiceInformation(aServiceInfo);
if (eChange.isUnchanged()) {
// Most likely an internal error or an inconsistency
throw new SMPNotFoundException("serviceInformation(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - ServiceInformation");
STATS_COUNTER_SUCCESS.increment(sAction);
} else {
// No Service Info, so should be a redirect
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
if (aRedirect != null) {
// Handle redirect
final EChange eChange = aRedirectMgr.deleteSMPRedirect(aRedirect);
if (eChange.isUnchanged()) {
// Most likely an internal error or an inconsistency
throw new SMPNotFoundException("redirect(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - Redirect");
STATS_COUNTER_SUCCESS.increment(sAction);
} else {
// Neither redirect nor endpoint found
throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
}
}
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class SMPServerAPI method deleteServiceRegistrations.
public void deleteServiceRegistrations(@Nonnull final String sPathServiceGroupID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/";
final String sAction = "deleteServiceRegistrations";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
EChange eChange = aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aServiceGroup);
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
eChange = eChange.or(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aServiceGroup));
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS - " + eChange);
STATS_COUNTER_SUCCESS.increment(sAction);
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class SMPBusinessCardManagerJDBC method getAllSMPBusinessCards.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPBusinessCard> getAllSMPBusinessCards() {
final ICommonsList<ISMPBusinessCard> ret = new CommonsArrayList<>();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT id, pid, name, country, geoinfo, identifiers, websites, contacts, addon, regdate" + " FROM smp_bce");
if (aDBResult != null) {
final IIdentifierFactory aIF = SMPMetaManager.getIdentifierFactory();
// Group by ID
final ICommonsMap<IParticipantIdentifier, ICommonsList<SMPBusinessCardEntity>> aEntityMap = new CommonsHashMap<>();
for (final DBResultRow aRow : aDBResult) {
final SMPBusinessCardEntity aEntity = new SMPBusinessCardEntity(aRow.getAsString(0));
// Single name only
aEntity.names().add(new SMPBusinessCardName(aRow.getAsString(2), null));
aEntity.setCountryCode(aRow.getAsString(3));
aEntity.setGeographicalInformation(aRow.getAsString(4));
aEntity.identifiers().setAll(getJsonAsBCI(aRow.getAsString(5)));
aEntity.websiteURIs().setAll(getJsonAsString(aRow.getAsString(6)));
aEntity.contacts().setAll(getJsonAsBCC(aRow.getAsString(7)));
aEntity.setAdditionalInformation(aRow.getAsString(8));
aEntity.setRegistrationDate(aRow.get(9).getAsLocalDate());
aEntityMap.computeIfAbsent(aIF.parseParticipantIdentifier(aRow.getAsString(1)), k -> new CommonsArrayList<>()).add(aEntity);
}
// Convert
for (final Map.Entry<IParticipantIdentifier, ICommonsList<SMPBusinessCardEntity>> aEntry : aEntityMap.entrySet()) {
final IParticipantIdentifier aPID = aEntry.getKey();
ret.add(new SMPBusinessCard(aPID, aEntry.getValue()));
}
}
return ret;
}
Aggregations