Search in sources :

Example 11 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class ProcessResultDAOImplTest method testRetrieveGrossResultFromAuditAndWebResource.

public void testRetrieveGrossResultFromAuditAndWebResource() {
    Audit audit = auditDAO.read(Long.valueOf(1));
    WebResource wr = webresourceDAO.read(Long.valueOf(1));
    Collection<ProcessResult> processResultList = processResultDAO.retrieveNetResultFromAuditAndWebResource(audit, wr);
    assertEquals(6, processResultList.size());
    wr = webresourceDAO.read(Long.valueOf(2));
    processResultList = processResultDAO.retrieveNetResultFromAuditAndWebResource(audit, wr);
    assertEquals(0, processResultList.size());
}
Also used : Audit(org.asqatasun.entity.audit.Audit) ProcessResult(org.asqatasun.entity.audit.ProcessResult) WebResource(org.asqatasun.entity.subject.WebResource)

Example 12 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class ContentLoaderImpl method run.

private List<Content> run(WebResource webResource) {
    // TODO Handle exceptions like 404, 403, 500, ...
    List<Content> localResult = new ArrayList<>();
    if (webResource instanceof Page) {
        downloader.setURL(webResource.getURL());
        downloader.run();
        String stringContent = downloader.getResult();
        Content content = contentDataService.getSSP(dateFactory.createDate(), webResource.getURL(), stringContent, (Page) webResource, HTTP_CODE_OK);
        localResult.add(content);
    }
    if (webResource instanceof Site) {
        Site site = (Site) webResource;
        for (WebResource component : site.getComponentList()) {
            localResult.addAll(run(component));
        }
    }
    return localResult;
}
Also used : Site(org.asqatasun.entity.subject.Site) Content(org.asqatasun.entity.audit.Content) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) Page(org.asqatasun.entity.subject.Page)

Example 13 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class FileContentLoaderImpl method run.

/**
     * 
     * @param webResource
     * @return 
     */
private List<Content> run(WebResource webResource) {
    List<Content> localResult = new ArrayList<>();
    if (webResource instanceof Page) {
        Content content = contentDataService.getSSP(dateFactory.createDate(), webResource.getURL(), fileMap.get(FileNaming.removeFilePrefix(webResource.getURL())), (Page) webResource, HttpStatus.SC_OK);
        localResult.add(content);
    } else if (webResource instanceof Site) {
        Site site = (Site) webResource;
        for (WebResource component : site.getComponentList()) {
            localResult.addAll(run(component));
        }
    }
    return localResult;
}
Also used : Site(org.asqatasun.entity.subject.Site) Content(org.asqatasun.entity.audit.Content) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) Page(org.asqatasun.entity.subject.Page)

Example 14 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class ContentLoaderServiceImplTest method testLoadContent_WebResource.

/**
     * Test of loadContent method, of class ContentLoaderServiceImpl.
     */
public void testLoadContent_WebResource() {
    System.out.println("loadContent");
    WebResource mockWebResource = EasyMock.createMock(WebResource.class);
    ContentDataService mockContentDataService = EasyMock.createMock(ContentDataService.class);
    Downloader mockDownloader = EasyMock.createMock(Downloader.class);
    DownloaderFactory mockDownloaderFactory = EasyMock.createMock(DownloaderFactory.class);
    ContentLoaderFactory mockContentLoaderFactory = EasyMock.createMock(ContentLoaderFactory.class);
    ContentLoader mockContentLoader = EasyMock.createMock(ContentLoader.class);
    DateFactory mockDateFactory = EasyMock.createMock(DateFactory.class);
    EasyMock.expect(mockDownloaderFactory.create()).andReturn(mockDownloader).once();
    EasyMock.expect(mockContentLoaderFactory.create(mockContentDataService, mockDownloader, mockDateFactory, null)).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(mockDownloader);
    EasyMock.replay(mockDownloaderFactory);
    EasyMock.replay(mockDateFactory);
    ContentLoaderServiceImpl instance = new ContentLoaderServiceImpl();
    instance.setContentDataService(mockContentDataService);
    instance.setContentLoaderFactory(mockContentLoaderFactory);
    instance.setDownloaderFactory(mockDownloaderFactory);
    instance.setDateFactory(mockDateFactory);
    assertEquals(contentList, instance.loadContent(mockWebResource));
    EasyMock.verify(mockContent);
    EasyMock.verify(mockContentDataService);
    EasyMock.verify(mockContentLoader);
    EasyMock.verify(mockContentLoaderFactory);
    EasyMock.verify(mockDownloader);
    EasyMock.verify(mockDownloaderFactory);
    EasyMock.verify(mockDateFactory);
}
Also used : Content(org.asqatasun.entity.audit.Content) ContentLoader(org.asqatasun.contentloader.ContentLoader) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) Downloader(org.asqatasun.contentloader.Downloader) ContentLoaderFactory(org.asqatasun.contentloader.ContentLoaderFactory) DateFactory(org.asqatasun.util.factory.DateFactory) ContentDataService(org.asqatasun.entity.service.audit.ContentDataService) DownloaderFactory(org.asqatasun.contentloader.DownloaderFactory)

Example 15 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class CrawlerServiceImpl method crawl.

/**
     *
     * @param crawler
     * @param audit
     * @return
     */
private WebResource crawl(Crawler crawler, Audit audit, boolean persistOnTheFly) {
    crawler.run();
    WebResource wr = crawler.getResult();
    wr.setAudit(audit);
    audit.setSubject(wr);
    if (persistOnTheFly) {
        //the relation from webresource to audit is refresh, the audit has to
        // be persisted first
        auditDataService.saveOrUpdate(audit);
        setAuditToContent(wr, audit);
        removeSummerRomance(audit);
        removePageExcedent(wr, audit);
    }
    return wr;
}
Also used : WebResource(org.asqatasun.entity.subject.WebResource)

Aggregations

WebResource (org.asqatasun.entity.subject.WebResource)43 Audit (org.asqatasun.entity.audit.Audit)11 Content (org.asqatasun.entity.audit.Content)11 Site (org.asqatasun.entity.subject.Site)9 ArrayList (java.util.ArrayList)8 ProcessResult (org.asqatasun.entity.audit.ProcessResult)8 Page (org.asqatasun.entity.subject.Page)7 NoResultException (javax.persistence.NoResultException)6 Query (javax.persistence.Query)6 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)6 List (java.util.List)5 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 NonUniqueResultException (javax.persistence.NonUniqueResultException)3 SSP (org.asqatasun.entity.audit.SSP)3 ContentDataService (org.asqatasun.entity.service.audit.ContentDataService)3 Contract (org.asqatasun.webapp.entity.contract.Contract)3 Map (java.util.Map)2 ContentLoader (org.asqatasun.contentloader.ContentLoader)2 ContentLoaderFactory (org.asqatasun.contentloader.ContentLoaderFactory)2