Search in sources :

Example 11 with Content

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();
}
Also used : SSP(org.asqatasun.entity.audit.SSP) Content(org.asqatasun.entity.audit.Content) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 12 with Content

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");
    }
}
Also used : Content(org.asqatasun.entity.audit.Content) PersistenceException(javax.persistence.PersistenceException)

Example 13 with Content

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);
}
Also used : HashMap(java.util.HashMap) Content(org.asqatasun.entity.audit.Content) ContentLoader(org.asqatasun.contentloader.ContentLoader) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) ContentLoaderFactory(org.asqatasun.contentloader.ContentLoaderFactory) DateFactory(org.asqatasun.util.factory.DateFactory) ContentDataService(org.asqatasun.entity.service.audit.ContentDataService)

Example 14 with Content

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;
    }
}
Also used : SSP(org.asqatasun.entity.audit.SSP) Content(org.asqatasun.entity.audit.Content) RelatedContent(org.asqatasun.entity.audit.RelatedContent)

Example 15 with Content

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());
        }
    }
}
Also used : Content(org.asqatasun.entity.audit.Content) RelatedContent(org.asqatasun.entity.audit.RelatedContent) RelatedContent(org.asqatasun.entity.audit.RelatedContent)

Aggregations

Content (org.asqatasun.entity.audit.Content)17 WebResource (org.asqatasun.entity.subject.WebResource)11 ArrayList (java.util.ArrayList)7 SSP (org.asqatasun.entity.audit.SSP)5 Audit (org.asqatasun.entity.audit.Audit)4 ContentDataService (org.asqatasun.entity.service.audit.ContentDataService)3 ContentLoader (org.asqatasun.contentloader.ContentLoader)2 ContentLoaderFactory (org.asqatasun.contentloader.ContentLoaderFactory)2 AuditImpl (org.asqatasun.entity.audit.AuditImpl)2 ProcessResult (org.asqatasun.entity.audit.ProcessResult)2 RelatedContent (org.asqatasun.entity.audit.RelatedContent)2 Test (org.asqatasun.entity.reference.Test)2 Page (org.asqatasun.entity.subject.Page)2 Site (org.asqatasun.entity.subject.Site)2 ScenarioLoader (org.asqatasun.scenarioloader.ScenarioLoader)2 DateFactory (org.asqatasun.util.factory.DateFactory)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1