Search in sources :

Example 36 with Parameter

use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.

the class ParameterDataServiceDecoratorImpl method getParameterSetFromOptionElementSet.

@Override
public Collection<Parameter> getParameterSetFromOptionElementSet(Collection<OptionElement> optionElementSet) {
    Set<Parameter> paramSet = new HashSet<>();
    for (OptionElement optionElement : optionElementSet) {
        ParameterElement pe = parameterElementDataService.getParameterElement(optionElement.getOption().getCode());
        if (pe != null) {
            Parameter p = decoratedParameterDataService.getParameter(pe, optionElement.getValue());
            p = saveOrUpdate(p);
            paramSet.add(p);
        }
    }
    return paramSet;
}
Also used : OptionElement(org.asqatasun.webapp.entity.option.OptionElement) Parameter(org.asqatasun.entity.parameterization.Parameter) ParameterElement(org.asqatasun.entity.parameterization.ParameterElement) HashSet(java.util.HashSet)

Example 37 with Parameter

use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.

the class AuditServiceImplTest method testAuditSite.

/**
     * Test of auditPage method, of class AuditServiceImpl.
     */
public void testAuditSite() {
    System.out.println("auditSite");
    String siteUrl = "http://My.testUrl.org";
    Set<Parameter> paramSet = null;
    AuditServiceImpl instance = initialiseAuditService();
    Audit auditCreateByAuditCommand = EasyMock.createMock(Audit.class);
    AuditCommand mockAuditCommand = EasyMock.createMock(AuditCommand.class);
    EasyMock.expect(mockAuditCommand.getAudit()).andReturn(auditCreateByAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommand);
    AuditCommandFactory mockAuditCommandFactory = EasyMock.createMock(AuditCommandFactory.class);
    EasyMock.expect(mockAuditCommandFactory.create(siteUrl, paramSet, true)).andReturn(mockAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommandFactory);
    instance.setAuditCommandFactory(mockAuditCommandFactory);
    // anyTimes the audit is created and set-up, the auditServiceThreadQueue is 
    // called to effectively launch the site audit
    AuditServiceThreadQueue mockAuditServiceThreadQueue = EasyMock.createMock(AuditServiceThreadQueue.class);
    mockAuditServiceThreadQueue.add(instance);
    EasyMock.expectLastCall().anyTimes();
    mockAuditServiceThreadQueue.addSiteAudit(mockAuditCommand);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(mockAuditServiceThreadQueue);
    instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
    Audit result = instance.auditSite(siteUrl, paramSet);
    assertEquals(auditCreateByAuditCommand, result);
    EasyMock.verify(mockAuditServiceThreadQueue);
    EasyMock.verify(mockAuditCommand);
    EasyMock.verify(mockAuditCommandFactory);
}
Also used : Audit(org.asqatasun.entity.audit.Audit) AuditCommandFactory(org.asqatasun.service.command.factory.AuditCommandFactory) Parameter(org.asqatasun.entity.parameterization.Parameter) AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 38 with Parameter

use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.

the class AuditServiceImplTest method testAuditPage.

/**
     * Test of auditPage method, of class AuditServiceImpl.
     */
public void testAuditPage() {
    System.out.println("auditPage");
    String pageUrl = "http://My.testUrl.org";
    Set<Parameter> paramSet = null;
    AuditServiceImpl instance = initialiseAuditService();
    Audit auditCreateByAuditCommand = EasyMock.createMock(Audit.class);
    AuditCommand mockAuditCommand = EasyMock.createMock(AuditCommand.class);
    EasyMock.expect(mockAuditCommand.getAudit()).andReturn(auditCreateByAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommand);
    AuditCommandFactory mockAuditCommandFactory = EasyMock.createMock(AuditCommandFactory.class);
    EasyMock.expect(mockAuditCommandFactory.create(pageUrl, paramSet, false)).andReturn(mockAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommandFactory);
    instance.setAuditCommandFactory(mockAuditCommandFactory);
    // anyTimes the audit is created and set-up, the auditServiceThreadQueue is 
    // called to effectively launch the page audit
    AuditServiceThreadQueue mockAuditServiceThreadQueue = EasyMock.createMock(AuditServiceThreadQueue.class);
    mockAuditServiceThreadQueue.add(instance);
    EasyMock.expectLastCall().anyTimes();
    mockAuditServiceThreadQueue.addPageAudit(mockAuditCommand);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(mockAuditServiceThreadQueue);
    instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
    Audit result = instance.auditPage(pageUrl, paramSet);
    assertEquals(auditCreateByAuditCommand, result);
    EasyMock.verify(mockAuditServiceThreadQueue);
    EasyMock.verify(mockAuditCommand);
    EasyMock.verify(mockAuditCommandFactory);
}
Also used : Audit(org.asqatasun.entity.audit.Audit) AuditCommandFactory(org.asqatasun.service.command.factory.AuditCommandFactory) Parameter(org.asqatasun.entity.parameterization.Parameter) AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 39 with Parameter

use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.

the class AuditServiceImplTest method testAuditPageUploadWithOneFile.

/**
     * Test of auditPageUpload method, of class AuditServiceImpl.
     */
public void testAuditPageUploadWithOneFile() {
    System.out.println("auditPageUploadWithOneFile");
    Set<Parameter> paramSet = null;
    // test we only one file is passed as argument to be tested
    String file1Name = "file://test1";
    Map<String, String> fileMap = new HashMap<>();
    fileMap.put(file1Name, "");
    AuditServiceImpl instance = initialiseAuditService();
    Audit auditCreateByAuditCommand = EasyMock.createMock(Audit.class);
    AuditCommand mockAuditCommand = EasyMock.createMock(AuditCommand.class);
    EasyMock.expect(mockAuditCommand.getAudit()).andReturn(auditCreateByAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommand);
    AuditCommandFactory mockAuditCommandFactory = EasyMock.createMock(AuditCommandFactory.class);
    EasyMock.expect(mockAuditCommandFactory.create(fileMap, paramSet)).andReturn(mockAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommandFactory);
    instance.setAuditCommandFactory(mockAuditCommandFactory);
    // anyTimes the audit is created and set-up, the auditServiceThreadQueue is 
    // called to effectively launch the pageUpload audit
    AuditServiceThreadQueue mockAuditServiceThreadQueue = EasyMock.createMock(AuditServiceThreadQueue.class);
    mockAuditServiceThreadQueue.add(instance);
    EasyMock.expectLastCall().anyTimes();
    mockAuditServiceThreadQueue.addPageUploadAudit(mockAuditCommand);
    EasyMock.replay(mockAuditServiceThreadQueue);
    instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
    Audit result = instance.auditPageUpload(fileMap, paramSet);
    assertEquals(auditCreateByAuditCommand, result);
    EasyMock.verify(mockAuditServiceThreadQueue);
    EasyMock.verify(mockAuditCommand);
    EasyMock.verify(mockAuditCommandFactory);
}
Also used : Audit(org.asqatasun.entity.audit.Audit) AuditCommandFactory(org.asqatasun.service.command.factory.AuditCommandFactory) Parameter(org.asqatasun.entity.parameterization.Parameter) AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 40 with Parameter

use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.

the class AsqatasunCrawlJob method initializeCrawlContext.

/**
     * 
     * @param url
     * @param crawlParameterSet
     * @param heritrixFileName
     * @return
     */
private File initializeCrawlContext(Collection<String> urlList, Set<Parameter> crawlParameterSet, String heritrixFileName) {
    buildOutputDirectory();
    BufferedReader in = null;
    FileWriter fw = null;
    try {
        LOGGER.debug("crawlConfigFilePath: " + crawlConfigFilePath + " for copy");
        String filepath = crawlConfigFilePath + "/" + heritrixFileName;
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(filepath);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("filepath : " + filepath);
            for (Parameter param : crawlParameterSet) {
                LOGGER.debug(param.getParameterElement().getParameterElementCode() + " " + param.getValue());
            }
        }
        doc = setOptionToDocument(urlList, crawlParameterSet, doc);
        //write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        String resultFileName = currentJobOutputDir.getPath() + "/" + heritrixFileName;
        StreamResult result = new StreamResult(new File(resultFileName));
        transformer.transform(source, result);
    } catch (IOException | ParserConfigurationException | SAXException ex) {
        LOGGER.error(ex);
        throw new CrawlerException(ex);
    } catch (TransformerConfigurationException ex) {
        LOGGER.error(ex);
        throw new CrawlerException(ex);
    } catch (TransformerException ex) {
        LOGGER.error(ex);
        throw new CrawlerException(ex);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ex) {
                LOGGER.error(ex);
                throw new CrawlerException(ex);
            }
        }
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException ex) {
                LOGGER.error(ex);
                throw new CrawlerException(ex);
            }
        }
    }
    return new File(currentJobOutputDir.getPath() + "/" + heritrixFileName);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Document(org.w3c.dom.Document) CrawlerException(org.asqatasun.crawler.exception.CrawlerException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) BufferedReader(java.io.BufferedReader) Parameter(org.asqatasun.entity.parameterization.Parameter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

Parameter (org.asqatasun.entity.parameterization.Parameter)59 ParameterElement (org.asqatasun.entity.parameterization.ParameterElement)13 Audit (org.asqatasun.entity.audit.Audit)8 ParameterImpl (org.asqatasun.entity.parameterization.ParameterImpl)6 NoResultException (javax.persistence.NoResultException)5 Query (javax.persistence.Query)5 HashSet (java.util.HashSet)4 AuditCommand (org.asqatasun.service.command.AuditCommand)4 AuditCommandFactory (org.asqatasun.service.command.factory.AuditCommandFactory)4 Test (org.junit.Test)4 File (java.io.File)3 IOException (java.io.IOException)3 Crawler (org.asqatasun.crawler.Crawler)3 ParameterElementImpl (org.asqatasun.entity.parameterization.ParameterElementImpl)3 LinkedHashSet (java.util.LinkedHashSet)2 ParameterFamily (org.asqatasun.entity.parameterization.ParameterFamily)2 WebResourceStatisticsDataService (org.asqatasun.entity.service.statistics.WebResourceStatisticsDataService)2 WebResourceStatisticsDataServiceImpl (org.asqatasun.entity.service.statistics.WebResourceStatisticsDataServiceImpl)2 WebResourceStatistics (org.asqatasun.entity.statistics.WebResourceStatistics)2 WebResourceStatisticsFactory (org.asqatasun.entity.statistics.factory.WebResourceStatisticsFactory)2