use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class AbstractRuleImplementationTestCase method setUpClass.
/**
*
*/
private void setUpClass() {
Test test = TEST_FACTORY.create();
test.setCode(this.getName());
test.setRuleClassName(ruleImplementationClassName);
test.setRuleArchiveName("MockArchiveName");
testList.add(test);
URL src = null;
LOGGER.info("setUpClass()");
for (WebResource webResource : webResourceMap.values()) {
LOGGER.info("webResource.getURL() " + webResource.getURL());
contentMap.put(webResource, CONTENT_LOADER_SERVICE.loadContent(webResource));
if (relatedContentMap.get(webResource) != null) {
for (String contentUrl : relatedContentMap.get(webResource)) {
if (contentMap.get(webResource).get(0) instanceof SSP) {
SSP ssp = (SSP) contentMap.get(webResource).get(0);
try {
src = new URL(ssp.getURI());
URL_IDENTIFIER.setUrl(src);
} catch (MalformedURLException ex) {
LOGGER.error(ex);
}
URL_IDENTIFIER.setUrl(src);
String relatedContentUrl = URL_IDENTIFIER.resolve(contentUrl).toExternalForm();
if (isContentCss(relatedContentUrl)) {
ssp.addRelatedContent(CONTENT_FACTORY.createStylesheetContent(new Date(), relatedContentUrl, ssp, getTextContent(relatedContentUrl), 200));
} else {
ssp.addRelatedContent(CONTENT_FACTORY.createImageContent(new Date(), relatedContentUrl, ssp, getBinaryImage(relatedContentUrl), 200));
}
}
}
}
contentMap.put(webResource, (List<Content>) CONTENT_ADAPTER_SERVICE.adaptContent((contentMap.get(webResource))));
}
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class UploadAuditCommandImpl method createWebResources.
private void createWebResources() {
WebResource webResource;
if (fileMap.size() > 1) {
webResource = getWebResourceDataService().createSite(FileNaming.addProtocolToUrl(fileMap.keySet().iterator().next()));
getWebResourceDataService().saveOrUpdate(webResource);
for (String pageUrl : fileMap.keySet()) {
Page page = getWebResourceDataService().createPage(pageUrl);
((Site) webResource).addChild(page);
getWebResourceDataService().saveOrUpdate(page);
}
} else {
webResource = getWebResourceDataService().createPage(fileMap.keySet().iterator().next());
}
// the webresource needs to be persisted a second time because of the
// relation with the audit
webResource.setAudit(getAudit());
getWebResourceDataService().saveOrUpdate(webResource);
getAudit().setSubject(webResource);
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class AuditCommandImpl method analyse.
@Override
public void analyse() {
audit = auditDataService.read(audit.getId());
if (!audit.getStatus().equals(AuditStatus.ANALYSIS)) {
LOGGER.warn(new StringBuilder(AUDIT_STATUS_IS_LOGGER_STR).append(audit.getStatus()).append(WHILE_LOGGER_STR).append(AuditStatus.ANALYSIS).append(WAS_REQUIRED_LOGGER_STR).toString());
return;
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Analysing " + audit.getSubject().getURL());
}
// debug tools
Date beginProcessDate = null;
Date endProcessDate = null;
Date endPersistDate;
Long persistenceDuration = (long) 0;
WebResource parentWebResource = audit.getSubject();
if (parentWebResource instanceof Page) {
analyserService.analyse(parentWebResource, audit);
webResourceDataService.saveOrUpdate(parentWebResource);
} else if (parentWebResource instanceof Site) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Analysing results of scope site");
beginProcessDate = Calendar.getInstance().getTime();
}
analyserService.analyse(parentWebResource, audit);
if (LOGGER.isDebugEnabled()) {
endProcessDate = Calendar.getInstance().getTime();
LOGGER.debug(new StringBuilder("Analysing results of scope site took ").append(endProcessDate.getTime() - beginProcessDate.getTime()).append(MS_LOGGER_STR).toString());
}
webResourceDataService.saveOrUpdate(parentWebResource);
if (LOGGER.isDebugEnabled()) {
endPersistDate = Calendar.getInstance().getTime();
LOGGER.debug(new StringBuilder("Persisting Analysis results of scope site ").append(endPersistDate.getTime() - endProcessDate.getTime()).append(MS_LOGGER_STR).toString());
persistenceDuration = persistenceDuration + (endPersistDate.getTime() - endProcessDate.getTime());
}
Long nbOfContent = webResourceDataService.getNumberOfChildWebResource(parentWebResource);
Long i = (long) 0;
List<WebResource> webResourceList;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(new StringBuilder("Analysing ").append(nbOfContent).append(" elements ").toString());
}
while (i.compareTo(nbOfContent) < 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(new StringBuilder("Analysing results of scope page from ").append(i).append(TO_LOGGER_STR).append(i + analyseTreatmentWindow).toString());
beginProcessDate = Calendar.getInstance().getTime();
}
webResourceList = webResourceDataService.getWebResourceFromItsParent(parentWebResource, i.intValue(), analyseTreatmentWindow);
for (WebResource webResource : webResourceList) {
if (LOGGER.isDebugEnabled()) {
endProcessDate = Calendar.getInstance().getTime();
LOGGER.debug(new StringBuilder("Analysing results for page ").append(webResource.getURL()).append(" took ").append(endProcessDate.getTime() - beginProcessDate.getTime()).append(MS_LOGGER_STR).toString());
}
analyserService.analyse(webResource, audit);
if (LOGGER.isDebugEnabled()) {
endPersistDate = Calendar.getInstance().getTime();
LOGGER.debug(new StringBuilder("Persisting Analysis results for page ").append(webResource.getURL()).append(" took ").append(endPersistDate.getTime() - endProcessDate.getTime()).append(MS_LOGGER_STR).toString());
persistenceDuration = persistenceDuration + (endPersistDate.getTime() - endProcessDate.getTime());
}
}
i = i + analyseTreatmentWindow;
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(new StringBuilder("Application spent ").append(persistenceDuration).append(" ms to write in Disk while analysing").toString());
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info(audit.getSubject().getURL() + " has been analysed");
}
setStatusToAudit(AuditStatus.COMPLETED);
if (cleanUpRelatedContent) {
cleanUpTestData(audit);
}
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class AbstractGroupRuleWithPageResultImplementation method consolidateImpl.
/**
* This is the implementation of the method declared in
* {@link AbstractRuleImplementation}. It encapsulates the main algorithm of
* the consolidation operation of concrete {@link RuleImplementation}
* classes for tests with group scope. It calls the method
* {@link #consolidateGroup(org.asqatasun.entity.subject.Site, java.util.Set)}
* which should consolidate gross results by group. In common cases, this
* method should not be overriden.
*
* @param grossResultMap
* the gross result map to consolidate.
* @return the list of net results from the gross result list.
*/
@Override
protected List<ProcessResult> consolidateImpl(Map<WebResource, List<ProcessResult>> grossResultMap, ProcessRemarkService processRemarkService) {
List<ProcessResult> netResultList = new ArrayList<>();
for (Map.Entry<WebResource, List<ProcessResult>> entry : grossResultMap.entrySet()) {
WebResource key = entry.getKey();
List<ProcessResult> grossResultList = entry.getValue();
if (entry.getKey() instanceof Page) {
DefiniteResult netResult = processResultDataService.getDefiniteResult(test, key);
netResult.setDefiniteValue(TestSolution.NOT_APPLICABLE);
for (ProcessResult grossResult : grossResultList) {
// netResult.addChildResult(grossResult);
netResult.setNetResultAudit(grossResult.getGrossResultAudit());
}
netResultList.add(netResult);
continue;
} else {
netResultList.addAll(consolidateGroup((Site) key, grossResultList, processRemarkService));
}
}
return consolidateSite(netResultList, processRemarkService);
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class ProcessResultDAOImplTest method testGetResultByScopeList.
public void testGetResultByScopeList() {
Scope scope1 = scopeDAO.read(Long.valueOf(1));
Scope scope2 = scopeDAO.read(Long.valueOf(2));
WebResource wa = webresourceDAO.read(Long.valueOf(1));
assertEquals(1, processResultDAO.getResultByScopeList(wa, scope2).size());
assertEquals(5, processResultDAO.getResultByScopeList(wa, scope1).size());
}
Aggregations