use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class AuditCommandImplTest method testAdaptContent.
/**
* Test of adaptContent method, of class AuditCommandImpl.
*/
public void testAdaptContent() {
System.out.println("adaptContent");
mockInitialisationCalls(false, null);
WebResource mockWr = createMock(WebResource.class);
expect(mockAudit.getId()).andReturn(Long.valueOf(1)).once();
expect(mockAuditDataService.read(Long.valueOf(1))).andReturn(mockAudit).once();
expect(mockAudit.getStatus()).andReturn(AuditStatus.CONTENT_ADAPTING).once();
expect(mockAudit.getSubject()).andReturn(mockWr).anyTimes();
expect(mockWr.getURL()).andReturn("").anyTimes();
expect(mockWr.getId()).andReturn(Long.valueOf(1)).once();
expect(mockContentDataService.getNumberOfSSPFromWebResource(mockWr, HttpStatus.SC_OK)).andReturn(Long.valueOf(49)).once();
expect(mockContentDataService.getSSPFromWebResource(Long.valueOf(1), Long.valueOf(0), 25, true)).andReturn(new ArrayList<Content>()).once();
expect(mockContentDataService.getSSPFromWebResource(Long.valueOf(1), Long.valueOf(25), 25, true)).andReturn(new ArrayList<Content>()).once();
// the adaptContent must return at least one non empty SSP
SSP mockSSP = createMock(SSP.class);
expect(mockSSP.getDOM()).andReturn("Not Empty String").times(3);
expect(mockSSP.getSource()).andReturn("Not Empty String").times(2);
try {
mockSSP.setSource(MD5Encoder.MD5("Not Empty String"));
expectLastCall().times(2);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
Logger.getLogger(this.getClass()).error(ex);
}
List<Content> mockAdaptedContentList = new ArrayList<>();
mockAdaptedContentList.add(mockSSP);
expect(mockContentAdapterService.adaptContent(new ArrayList<Content>())).andReturn(mockAdaptedContentList).times(2);
expect(mockContentDataService.saveOrUpdate(mockSSP)).andReturn(mockSSP).times(2);
mockAudit.setStatus(AuditStatus.PROCESSING);
expectLastCall().once();
expect(mockAuditDataService.saveOrUpdate(mockAudit)).andReturn(mockAudit).once();
replay(mockWr);
replay(mockContentDataService);
replay(mockContentAdapterService);
replay(mockSSP);
setReplayMode();
AuditCommandImpl instance = new TestAuditCommandImpl();
instance.adaptContent();
verify(mockContentDataService);
verify(mockContentAdapterService);
verify(mockWr);
verify(mockSSP);
setVerifyMode();
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class UploadAuditCommandImpl method loadContent.
@Override
public void loadContent() {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Loading files content " + fileMap);
}
if (!getAudit().getStatus().equals(AuditStatus.CONTENT_LOADING) || fileMap.isEmpty()) {
LOGGER.warn(new StringBuilder("Audit Status is ").append(getAudit().getStatus()).append(" while ").append(AuditStatus.CONTENT_LOADING).append(" was required ").toString());
setStatusToAudit(AuditStatus.ERROR);
return;
}
createWebResources();
//call the load content service to convert files into SSP and link it
//to the appropriate webResource
List<Content> contentList = contentLoaderService.loadContent(getAudit().getSubject(), fileMap);
for (Content content : contentList) {
content.setAudit(getAudit());
try {
getContentDataService().saveOrUpdate(content);
} catch (PersistenceException pe) {
getAudit().setStatus(AuditStatus.ERROR);
break;
}
}
setStatusToAudit(AuditStatus.CONTENT_ADAPTING);
if (LOGGER.isInfoEnabled()) {
LOGGER.info(fileMap + " has been loaded");
}
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class ContentLoaderServiceImplTest method testLoadContent_WebResource_Map.
/**
* Test of loadContent method, of class ContentLoaderServiceImpl.
*/
public void testLoadContent_WebResource_Map() {
System.out.println("loadContent with file Map");
WebResource mockWebResource = EasyMock.createMock(WebResource.class);
ContentDataService mockContentDataService = EasyMock.createMock(ContentDataService.class);
ContentLoaderFactory mockContentLoaderFactory = EasyMock.createMock(ContentLoaderFactory.class);
DateFactory mockDateFactory = EasyMock.createMock(DateFactory.class);
ContentLoader mockContentLoader = EasyMock.createMock(ContentLoader.class);
Map<String, String> fileMap = new HashMap<>();
EasyMock.expect(mockContentLoaderFactory.create(mockContentDataService, null, mockDateFactory, fileMap)).andReturn(mockContentLoader).once();
mockContentLoader.setWebResource(mockWebResource);
EasyMock.expectLastCall().once();
mockContentLoader.run();
EasyMock.expectLastCall().once();
List<Content> contentList = new ArrayList<>();
Content mockContent = EasyMock.createMock(Content.class);
contentList.add(mockContent);
EasyMock.expect(mockContentLoader.getResult()).andReturn(contentList).once();
EasyMock.replay(mockContent);
EasyMock.replay(mockContentDataService);
EasyMock.replay(mockContentLoader);
EasyMock.replay(mockContentLoaderFactory);
EasyMock.replay(mockDateFactory);
ContentLoaderServiceImpl instance = new ContentLoaderServiceImpl();
instance.setContentDataService(mockContentDataService);
instance.setContentLoaderFactory(mockContentLoaderFactory);
instance.setDateFactory(mockDateFactory);
assertEquals(contentList, instance.loadContent(mockWebResource, fileMap));
EasyMock.verify(mockContent);
EasyMock.verify(mockContentDataService);
EasyMock.verify(mockContentLoader);
EasyMock.verify(mockContentLoaderFactory);
EasyMock.verify(mockDateFactory);
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class CrawlerServiceImpl method removePageExcedent.
/**
* During the crawl, more Webresources and Contents than expected may
* be retrieved. This methods delete them.
*
* @param webResource
* @param audit
*/
private void removePageExcedent(WebResource wr, Audit audit) {
int maxNumberOfCrawlPage = getMaxNumberOfCrawlPageFromAuditParameter(audit);
// httpStatusCode = -1 means all.
int httpStatusCode = -1;
Long nbOfContent = contentDataService.getNumberOfSSPFromWebResource(wr, httpStatusCode);
if (maxNumberOfCrawlPage == -1 || nbOfContent < maxNumberOfCrawlPage) {
return;
}
Long i = (long) maxNumberOfCrawlPage + 1;
Long fromValue = (long) maxNumberOfCrawlPage;
LOGGER.info("Deleting " + (nbOfContent - maxNumberOfCrawlPage) + " content excedent regarding user limit");
while (i.compareTo(nbOfContent) < 0) {
Collection<Long> contentIdList = contentDataService.getSSPIdsFromWebResource(wr.getId(), httpStatusCode, fromValue.intValue(), PROCESS_WINDOW);
LOGGER.info("Delete excedent content from " + i + " to " + (i + PROCESS_WINDOW));
for (Long contentId : contentIdList) {
Content content = contentDataService.read(contentId);
if (content instanceof SSP) {
webResourceDataService.delete(((SSP) content).getPage().getId());
}
contentDataService.delete(contentId);
}
i = i + PROCESS_WINDOW;
}
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class CrawlerServiceImpl method removeSummerRomance.
/**
* During the crawl, Webresources and Contents are created. Contents can be
* of 2 types : SSP or relatedContent. A SSP is linked to a webResource and
* a relatedContent is linked to a SSP. The relation between a ssp and a
* relatedContent is not known when fetching. So we need to link all the
* relatedContent to any SSP to be able to link them to the current audit.
* At the end of the crawl, after the creation of the relation between a
* content and an audit, we can "clean" this fake relation.
*
* This method were supposed to be called removedFakeRelation but thanks to
* the scottish guy, this method is now called removerSummerRomance.
*
* @param webResource
* @param audit
*/
private void removeSummerRomance(Audit audit) {
Set<RelatedContent> relatedContentSet = (Set<RelatedContent>) contentDataService.getRelatedContentFromAudit(audit);
for (RelatedContent relatedContent : relatedContentSet) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" deleteContentRelationShip between of " + ((Content) relatedContent).getURI());
contentDataService.deleteContentRelationShip(((Content) relatedContent).getId());
}
}
}
Aggregations