/*
* C O P Y R I G H T N O T I C E
* -----------------------------------------------------------------------
* Copyright (c) 2011-2012 InfoClinika, Inc. 5901 152nd Ave SE, Bellevue, WA 98006,
* United States of America. (425) 442-8058. http://www.infoclinika.com.
* All Rights Reserved. Reproduction, adaptation, or translation without prior written permission of InfoClinika, Inc. is prohibited.
* Unpublished--rights reserved under the copyright laws of the United States. RESTRICTED RIGHTS LEGEND Use, duplication or disclosure by the
*/
package com.infoclinika.mssharing.search;
import com.infoclinika.msdata.image.SpectrumType;
import com.infoclinika.mssharing.fileserver.StorageService;
import com.infoclinika.mssharing.fileserver.impl.InMemoryStorageService;
import com.infoclinika.mssharing.model.Notifier;
import com.infoclinika.mssharing.model.Searcher;
import com.infoclinika.mssharing.model.internal.CriteriaRules;
import com.infoclinika.mssharing.model.internal.read.Transformers;
import com.infoclinika.mssharing.model.internal.repository.UserRepository;
import com.infoclinika.web.Service;
import com.infoclinika.web.dto.PreCachingResult;
import com.infoclinika.web.dto.TranslationRequest;
import com.infoclinika.web.dto.TranslationResult;
import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
import javax.persistence.EntityManagerFactory;
import java.util.ArrayList;
import java.util.Collections;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Stanislav Kurilin
*/
@Configuration
@ImportResource({"persistence.cfg.xml", "h2.cfg.xml"})
@ComponentScan(basePackages = {"com.infoclinika.mssharing.model", "com.infoclinika.mssharing.search"})
class SpringConfig {
@Bean
public StorageService inMemoryStorage() {
return new InMemoryStorageService();
}
@Bean
public Notifier notificator() {
return mock(Notifier.class);
}
@Bean
public Searcher searcher(EntityManagerFactory entityManagerFactory, Transformers transformers, UserRepository userRepository, CriteriaRules criteriaRules) {
final SearcherImpl searcher = new SearcherImpl(transformers, userRepository, criteriaRules);
searcher.setEntityManager(entityManagerFactory.createEntityManager());
searcher.initSearcher();
return searcher;
}
@Bean
public PasswordEncoder encoder() {
return new StandardPasswordEncoder();
}
@Bean(name = "translationService")
public Service translationService() {
Service translationService = mock(Service.class);
when(translationService.translateFiles(Matchers.<TranslationRequest>anyObject())).thenAnswer(new Answer<TranslationResult>() {
@Override
public TranslationResult answer(InvocationOnMock invocation) throws Throwable {
final TranslationResult result = new TranslationResult();
result.setTranslatedIds(new ArrayList<Long>(Collections.nCopies(7, 0L)));
return result;
}
});
when(translationService.preCacheChart(any(Long[].class), anyInt(), anyInt(), any(SpectrumType[].class), anyFloat(),
anyFloat(), anyDouble(), anyDouble())).thenAnswer(new Answer<PreCachingResult>() {
@Override
public PreCachingResult answer(InvocationOnMock invocation) throws Throwable {
return new PreCachingResult();
}
});
return translationService;
}
/*@Bean(name = "sequestSearchService")
public Service sequestSearchService() {
Service sequestSearchService = mock(Service.class);
// final SequestSearchPerFileWrapper sequestSearchPerFileWrapper = new SequestSearchPerFileWrapper(1L, getParams(), "");
// when(sequestSearchService.sequestSearchPerTranslatedFile(sequestSearchPerFileWrapper)).thenAnswer(new Answer<SequestSearchPerFileResultResponse>() {
// @Override
// public SequestSearchPerFileResultResponse answer(InvocationOnMock invocation) throws Throwable {
// return new SequestSearchPerFileResultResponse(
// sequestSearchPerFileWrapper,
// new S3ObjectReference("testBucket", "testSqtKey"),
// new S3ObjectReference("testBucket", "testSqtDecoyKey"),
// new S3ObjectReference("testBucket", "testResultsKey")
// );
// }
// });
return sequestSearchService;
}*/
/*protected static SearchParams getParams() {
final SearchParams searchParams = new SearchParams();
final SearchParams.ChangeableCometParams cometParams = new SearchParams.ChangeableCometParams();
final SearchParams.ChangeableCometParams.CometDatabaseParam db = new SearchParams.ChangeableCometParams.CometDatabaseParam();
db.setName("Escherichia Coli");
db.setBucketReference("chorus-development");
db.setKeyReference("fasta-dbs/EscherichiaColi.fasta");
cometParams.setDatabase(db);
cometParams.setPeptideMassTolerance(3.0);
cometParams.setMaxPrecursorCharge(6);
cometParams.setPeptideMassUnits(0);
cometParams.setMassTypeParent(1);
cometParams.setMassTypeFragment(1);
cometParams.setPrecursorToleranceType(0);
cometParams.setSearchEnzymeNumber(0);
cometParams.setNumEnzymeTermini(1);
cometParams.setSearchEnzymeNumber(0);
searchParams.setCometParams(cometParams);
final SearchParams.Ms2ProcessorParams ms2ProcessorParams = new SearchParams.Ms2ProcessorParams();
ms2ProcessorParams.setIsolationWidth(200000);
ms2ProcessorParams.setMaxCharge(7);
searchParams.setMs2ProcessorParams(ms2ProcessorParams);
final SearchParams.PercolatorParams percolatorParams = new SearchParams.PercolatorParams();
percolatorParams.setPercolatorParam(3);
searchParams.setPercolatorParams(percolatorParams);
return searchParams;
}*/
}