use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class IndexerResource method createOrUpdateParticipant.
@PUT
public Response createOrUpdateParticipant(@Context @Nonnull final HttpServletRequest aHttpServletRequest, @Nonnull final String sParticipantID) {
final String sLogPrefix = "[createOrUpdateParticipant] ";
final ClientCertificateValidationResult aResult = _checkClientCertificate(aHttpServletRequest, sLogPrefix);
if (aResult.isFailure())
return Response.status(Response.Status.FORBIDDEN).build();
final String sRealParticipantID = _unifyPID(sParticipantID);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLogPrefix + "'" + sRealParticipantID + "'");
// Parse identifier
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPI = aIdentifierFactory.parseParticipantIdentifier(sRealParticipantID);
if (aPI == null) {
if (LOGGER.isErrorEnabled())
LOGGER.error(sLogPrefix + "Failed to parse participant identifier '" + sRealParticipantID + "'");
return Response.status(Status.BAD_REQUEST).build();
}
// Queue for handling
if (PDMetaManager.getIndexerMgr().queueWorkItem(aPI, EIndexerWorkItemType.CREATE_UPDATE, aResult.getClientID(), _getRequestingHost(aHttpServletRequest)).isUnchanged()) {
if (LOGGER.isInfoEnabled())
LOGGER.info(sLogPrefix + "Ignoring duplicate CREATE/UPDATE request for '" + aPI.getURIEncoded() + "'");
}
// And done
return Response.noContent().build();
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class PDStorageManagerTest method testGetAllDocumentsOfCountryCode.
@Test
public void testGetAllDocumentsOfCountryCode() throws IOException {
final IParticipantIdentifier aParticipantID = PDMetaManager.getIdentifierFactory().createParticipantIdentifier("myscheme-actorid-upis", "0088:test");
assertNotNull(aParticipantID);
try (final PDStorageManager aMgr = new PDStorageManager(new PDLucene())) {
final PDStoredMetaData aMetaData = _createMockMetaData();
aMgr.createOrUpdateEntry(aParticipantID, _createMockBI(aParticipantID), aMetaData);
try {
// No country - no docs
ICommonsList<PDStoredBusinessEntity> aDocs = aMgr.getAllDocuments(new TermQuery(PDField.COUNTRY_CODE.getExactMatchTerm("")), -1);
assertEquals(0, aDocs.size());
// Search for NO
aDocs = aMgr.getAllDocuments(new TermQuery(PDField.COUNTRY_CODE.getExactMatchTerm("NO")), -1);
assertEquals(1, aDocs.size());
final PDStoredBusinessEntity aSingleDoc = aDocs.get(0);
assertEquals(aParticipantID, aSingleDoc.getParticipantID());
assertEquals("junittest", aSingleDoc.getMetaData().getOwnerID());
assertEquals("NO", aSingleDoc.getCountryCode());
} finally {
// Finally delete the entry again
aMgr.deleteEntry(aParticipantID, aMetaData, true);
}
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class PDStorageManagerTest method testGetAllDocumentsOfParticipant.
@Test
public void testGetAllDocumentsOfParticipant() throws IOException {
final IParticipantIdentifier aParticipantID = PDMetaManager.getIdentifierFactory().createParticipantIdentifier("myscheme-actorid-upis", "0088:test");
assertNotNull(aParticipantID);
try (final PDStorageManager aMgr = new PDStorageManager(new PDLucene())) {
final PDStoredMetaData aMetaData = _createMockMetaData();
aMgr.createOrUpdateEntry(aParticipantID, _createMockBI(aParticipantID), aMetaData);
try {
final ICommonsList<PDStoredBusinessEntity> aDocs = aMgr.getAllDocumentsOfParticipant(aParticipantID);
assertEquals(2, aDocs.size());
// Test entity 1
final PDStoredBusinessEntity aDoc1 = aDocs.get(0);
assertEquals(aParticipantID, aDoc1.getParticipantID());
assertEquals("junittest", aDoc1.getMetaData().getOwnerID());
assertEquals("AT", aDoc1.getCountryCode());
assertEquals(PDTFactory.createLocalDate(2015, Month.JULY, 6), aDoc1.getRegistrationDate());
assertEquals(1, aDoc1.names().size());
assertEquals("Philip's mock Peppol receiver", aDoc1.names().get(0).getName());
assertNull(aDoc1.names().get(0).getLanguageCode());
assertEquals("Vienna", aDoc1.getGeoInfo());
assertEquals(10, aDoc1.identifiers().size());
for (int i = 0; i < aDoc1.identifiers().size(); ++i) {
assertEquals("scheme" + i, aDoc1.identifiers().get(i).getScheme());
assertEquals("value" + i, aDoc1.identifiers().get(i).getValue());
}
assertEquals(1, aDoc1.websiteURIs().size());
assertEquals("http://www.peppol.eu", aDoc1.websiteURIs().get(0));
assertEquals(1, aDoc1.contacts().size());
assertEquals("support", aDoc1.contacts().get(0).getType());
assertEquals("BC name", aDoc1.contacts().get(0).getName());
assertEquals("test@example.org", aDoc1.contacts().get(0).getEmail());
assertEquals("12345", aDoc1.contacts().get(0).getPhone());
assertEquals("This is a mock entry for testing purposes only", aDoc1.getAdditionalInformation());
// Test entity 2
final PDStoredBusinessEntity aDoc2 = aDocs.get(1);
assertEquals(aParticipantID, aDoc2.getParticipantID());
assertEquals("junittest", aDoc2.getMetaData().getOwnerID());
assertEquals("NO", aDoc2.getCountryCode());
assertNull(aDoc2.getRegistrationDate());
assertEquals(3, aDoc2.names().size());
assertEquals("Entity2a", aDoc2.names().get(0).getName());
assertEquals("no", aDoc2.names().get(0).getLanguageCode());
assertEquals("Entity2b", aDoc2.names().get(1).getName());
assertEquals("de", aDoc2.names().get(1).getLanguageCode());
assertEquals("Entity2c", aDoc2.names().get(2).getName());
assertEquals("en", aDoc2.names().get(2).getLanguageCode());
assertNull(aDoc2.getGeoInfo());
assertEquals(0, aDoc2.identifiers().size());
assertEquals(0, aDoc2.websiteURIs().size());
assertEquals(0, aDoc2.contacts().size());
assertEquals("Mock", aDoc2.getAdditionalInformation());
} finally {
// Finally delete the entry again
aMgr.deleteEntry(aParticipantID, aMetaData, true);
}
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class LocalHost8080FuncTest method testCreateAndDeleteParticipant.
@Test
public void testCreateAndDeleteParticipant() throws IOException {
final AtomicInteger aIndex = new AtomicInteger(0);
final IParticipantIdentifier aPI_0 = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:test0");
final int nCount = 4;
CommonsTestHelper.testInParallel(nCount, () -> {
// Create
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:test" + aIndex.getAndIncrement());
LOGGER.info("PUT " + aPI.getURIEncoded());
final String sResponseMsg = m_aTarget.path("1.0").request().put(Entity.text(aPI.getURIEncoded()), String.class);
assertEquals("", sResponseMsg);
});
ThreadHelper.sleep(2000);
assertTrue(PDMetaManager.getStorageMgr().containsEntry(aPI_0, EQueryMode.ALL));
assertTrue(PDMetaManager.getStorageMgr().getCount(new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aPI_0))) > 0);
aIndex.set(0);
CommonsTestHelper.testInParallel(nCount, () -> {
// Delete
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:test" + aIndex.getAndIncrement());
LOGGER.info("DELETE " + aPI.getURIEncoded());
final String sResponseMsg = m_aTarget.path("1.0").path(aPI.getURIEncoded()).request().delete(String.class);
assertEquals("", sResponseMsg);
});
ThreadHelper.sleep(2000);
assertFalse(PDMetaManager.getStorageMgr().containsEntry(aPI_0, EQueryMode.NON_DELETED_ONLY));
assertEquals(0, PDMetaManager.getStorageMgr().getCount(EQueryMode.NON_DELETED_ONLY.getEffectiveQuery(new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aPI_0)))));
assertTrue(PDMetaManager.getStorageMgr().getCount(EQueryMode.DELETED_ONLY.getEffectiveQuery(new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aPI_0)))) > 0);
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class PublicParticipantXServletHandler method handleRequest.
public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
if (SearchRateLimit.INSTANCE.rateLimiter() != null) {
final String sRateLimitKey = "ip:" + aRequestScope.getRemoteAddr();
final boolean bOverLimit = SearchRateLimit.INSTANCE.rateLimiter().overLimitWhenIncremented(sRateLimitKey);
if (bOverLimit) {
// Too Many Requests
if (LOGGER.isDebugEnabled())
LOGGER.debug("Rate limit exceeded for " + sRateLimitKey);
aUnifiedResponse.setStatus(CHttp.HTTP_TOO_MANY_REQUESTS);
return;
}
}
// http://127.0.0.1:8080/participant -> null
// http://127.0.0.1:8080/participant/ -> "/"
// http://127.0.0.1:8080/participant/x -> "/x"
final String sPathInfo = StringHelper.getNotNull(aRequestScope.getPathInfo(), "");
final ICommonsList<String> aParts = StringHelper.getExploded('/', sPathInfo.substring(1));
IParticipantIdentifier aPI = null;
if (aParts.isNotEmpty()) {
final String sID = aParts.get(0);
aPI = PDMetaManager.getIdentifierFactory().parseParticipantIdentifier(sID);
if (aPI == null) {
// /participant/iso6523-actorid-upis/9915:test
if (aParts.size() >= 2) {
final String sScheme = sID;
final String sValue = aParts.get(1);
aPI = PDMetaManager.getIdentifierFactory().createParticipantIdentifier(sScheme, sValue);
}
}
if (aPI == null) {
// Still failure - try Peppol default scheme
aPI = PDMetaManager.getIdentifierFactory().createParticipantIdentifier(PeppolIdentifierFactory.INSTANCE.getDefaultParticipantIdentifierScheme(), sID);
}
}
if (aPI == null) {
LOGGER.error("Failed to resolve path '" + sPathInfo + "' to a participant ID!");
aUnifiedResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
// Redirect to search result page
final SimpleURL aTarget = RequestParameterManager.getInstance().getLinkToMenuItem(aRequestScope, AppCommonUI.DEFAULT_LOCALE, CMenuPublic.MENU_SEARCH_SIMPLE).add(CPageParam.PARAM_ACTION, CPageParam.ACTION_VIEW).add(PagePublicSearchSimple.FIELD_QUERY, aPI.getURIEncoded()).add(PagePublicSearchSimple.FIELD_PARTICIPANT_ID, aPI.getURIEncoded());
aUnifiedResponse.setRedirect(aTarget);
}
Aggregations