r307 - in wikengo_core-wikitty/wikengo_core-wikitty-api/src: main/java/org/sharengo/wikitty test/java/org/sharengo/wikitty test/java/org/sharengo/wikitty/test/api test/java/org/sharengo/wikitty/test/conform
Author: kmorin Date: 2009-11-04 11:18:51 +0100 (Wed, 04 Nov 2009) New Revision: 307 Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java Log: Separation of solr Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/AbstractWikittyService.java 2009-11-04 10:18:51 UTC (rev 307) @@ -1,16 +1,16 @@ /* *##% * Copyright (c) 2009 poussin. All rights reserved. - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. *##%*/ @@ -252,7 +252,7 @@ getSearchEngin().commit(transaction, indexCommands); } - + public PagedResult<Wikitty> findAllByCriteria(Criteria criteria) { PagedResult<String> resultId = getSearchEngin().findAllByCriteria(criteria); PagedResult<Wikitty> result = resultId.cast(getWikittyStorage()); @@ -270,7 +270,7 @@ } } - + public void addLabel(String wikittyId, String label) { Wikitty w = restore(wikittyId); w.addExtension(LabelImpl.extensions); @@ -279,7 +279,7 @@ store(l.getWikitty()); } - + public PagedResult<Wikitty> findAllByLabel(String label, int firstIndex, int endIndex) { LabelImpl l = new LabelImpl(); l.addLabels(label); @@ -289,7 +289,7 @@ return result; } - + public Wikitty findByLabel(String label) { LabelImpl l = new LabelImpl(); l.addLabels(label); @@ -298,7 +298,7 @@ return result; } - + public Set<String> findAllAppliedLabels(String wikittyId) { Wikitty w = restore(wikittyId); Label l = new LabelImpl(w); @@ -306,7 +306,7 @@ return result; } - + public Tree restoreTree(String wikittyId) { Wikitty w = restore(wikittyId); if(w == null) { @@ -321,7 +321,7 @@ Tree tree = new Tree(); TreeNode node = new TreeNodeImpl( w ); tree.setNode( node ); - + TreeNodeImpl exempleNode = new TreeNodeImpl(); exempleNode.setParent(wikittyId); @@ -337,7 +337,7 @@ tree.addElement(childrenId); } } - + return tree; } @@ -346,7 +346,7 @@ if(w == null) { return null; } - + if ( !w.hasExtension(TreeNode.EXT_TREENODE) ) { throw new WikittyException(String.format( "Wikitty '%s' do not handle extension %s", @@ -369,7 +369,7 @@ return result; } - + public Wikitty restoreVersion(String wikittyId, String version) { throw new UnsupportedOperationException("Not supported yet."); } @@ -433,7 +433,7 @@ } } - + public void syncImportFromXml(String xml) { Reader reader = new StringReader(xml); ImportTask task = new ImportTask(this, reader); @@ -452,7 +452,7 @@ } } - + public String asyncImportFromUri(String uri) { try { URL url = new URL(uri); @@ -460,7 +460,7 @@ ImportTask task = new ImportTask(this, reader); FutureTask<String> future = new FutureTask<String>(task, null); importExportExecutor.submit(future); - + String jobId = UUID.randomUUID().toString(); importExportTask.put(jobId, future); return jobId; @@ -478,7 +478,7 @@ this.ws = ws; this.reader = reader; } - + public void run() { try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance( @@ -558,7 +558,7 @@ } } } // end ImportTask - + public String asyncExportAllByCriteria(Criteria criteria) { try { criteria.setFirstIndex(0).setEndIndex(ALL_ELEMENTS); @@ -580,7 +580,7 @@ } } - + public String syncExportAllByCriteria(Criteria criteria) { criteria.setFirstIndex(0).setEndIndex(ALL_ELEMENTS); PagedResult<Wikitty> pageResult = findAllByCriteria(criteria); @@ -589,8 +589,8 @@ task.run(); return result.toString(); } - + static public class ExportTask implements Runnable { protected PagedResult<Wikitty> pageResult; protected Writer result; @@ -599,7 +599,7 @@ this.pageResult = pageResult; this.result = result; } - + public void run() { try { // keep extension already done @@ -644,7 +644,7 @@ } } // end ExportTask - + public JobState infoJob(String jobId) { try { Future<String> future = importExportTask.get(jobId); @@ -663,13 +663,13 @@ } } - + public void cancelJob(String jobId) { Future future = importExportTask.get(jobId); future.cancel(true); // true to kill process, perhaps to strong ? } - + public void freeJobResource(String jobId) { Future<String> future = importExportTask.remove(jobId); if (future != null) { Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/Tree.java 2009-11-04 10:18:51 UTC (rev 307) @@ -9,22 +9,22 @@ TreeNode node; List<Tree> children; // List<String> elements; - + public void setNode(TreeNode node) { this.node = node; } - + public void addChild(Tree tree) { getChildren().add( tree ); } - + public List<Tree> getChildren() { if ( children == null ) { children = new ArrayList<Tree>(); } return children; } - + public void addElement(String id) { node.addChildren(id); } @@ -32,7 +32,7 @@ public Set<String> getElements() { return node.getChildren(); } - + public String getName() { return node.getName(); } Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyProxy.java 2009-11-04 10:18:51 UTC (rev 307) @@ -42,7 +42,7 @@ static final public int ALL_ELEMENTS = WikittyService.ALL_ELEMENTS; protected WikittyService wikittyService; - + public WikittyService getWikittyService() { return wikittyService; } @@ -206,8 +206,6 @@ * needed by BusinessEntity (clazz). * @param clazz * @param criteria - * @param firstIndex - * @param endIndex * @return */ public <E extends BusinessEntity> PagedResult<E> findAllByCriteria( @@ -226,7 +224,7 @@ serviceCriteria.setFirstIndex(criteria.getFirstIndex()); serviceCriteria.setEndIndex(criteria.getEndIndex()); PagedResult<Wikitty> pagedResult = wikittyService.findAllByCriteria(serviceCriteria); - + // we can cast with autoconvert true because we have add restriction // on extension PagedResult<E> result = (PagedResult<E>)pagedResult.cast(sample.getClass(), true); @@ -296,11 +294,11 @@ } catch (Exception eee) { throw new WikittyException(eee); } - + // WikittyUtil.newInstance instanciate only BusinessEntityWikittyImpl BusinessEntityWikitty businessEntityImpl = (BusinessEntityWikitty) businessEntity; Collection<WikittyExtension> staticExtensions = businessEntityImpl.getStaticExtensions(); - + boolean goodType = true; for (Iterator<WikittyExtension> iterator = staticExtensions.iterator(); iterator.hasNext() && goodType;) { WikittyExtension ext = iterator.next(); Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyServiceInMemory.java 2009-11-04 10:18:51 UTC (rev 307) @@ -1,16 +1,16 @@ /* *##% * Copyright (c) 2009 poussin. All rights reserved. - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. *##%*/ @@ -60,13 +60,18 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(WikittyServiceInMemory.class); + @Override + public List<WikittyExtension> getAllExtensions(boolean lastVersion) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + class WikittyStorageInMemory implements WikittyStorage { protected Map<String, Wikitty> wikitties = new LinkedHashMap<String, Wikitty>(); public List<Command> prepare(WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean disableAutoVersionIncrement) throws WikittyException { - + List<Command> result = new ArrayList<Command>(wikitties.size()); for (Wikitty w : wikitties) { result.add(new CommandInMemory(w, true)); @@ -223,7 +228,7 @@ public WikittySearchEnginInMemory(WikittyStorageInMemory wikittyStorage) { this.wikittyStorage = wikittyStorage; } - + public void clear() { // do nothing } @@ -245,15 +250,15 @@ // do nothing return new ArrayList<Command>(); } - + public boolean checkRestriction( Restriction restriction, Wikitty w ) { if ( restriction instanceof BinaryOperator ) { BinaryOperator binOp = (BinaryOperator) restriction; - + if ( binOp.getElement().equals(Element.ELT_EXTENSION) ) { return w.hasExtension( (String) binOp.getValue() ); } - + String fqfieldName = binOp.getElement().getName(); Object o = w.getFqField( fqfieldName ); FieldType t = w.getFieldType(fqfieldName); @@ -279,13 +284,13 @@ checked = !value.equals(o); break; case ENDS_WITH: - if ( t.getType() != TYPE.STRING ) + if ( t.getType() != TYPE.STRING ) throw new WikittyException("Can't search for contents that 'ends with' on attribute type different of String. " + "Attribute " + fqfieldName + " is " + t.getType().name() ); checked = ((String) o).endsWith( (String) value ); break; case STARTS_WITH: - if ( t.getType() != TYPE.STRING ) + if ( t.getType() != TYPE.STRING ) throw new WikittyException("Can't search for contents that 'starts with' on attribute type different of String. " + "Attribute " + fqfieldName + " is " + t.getType().name() ); checked = ((String) o).startsWith( (String) value ); @@ -306,24 +311,24 @@ public PagedResult<String> findAllByCriteria( Criteria criteria) { // throw new UnsupportedOperationException("Not supported yet."); - + int firstIndex = criteria.getFirstIndex(); int endIndex = criteria.getEndIndex(); - + List<String> ids = new LinkedList<String>(); int currentIndex = 0; - + for( Entry<String, Wikitty> entry : wikittyStorage.wikitties.entrySet() ) { Wikitty w = entry.getValue(); String id = entry.getKey(); Restriction dto = criteria.getRestriction(); - + if ( checkRestriction(dto, w) ) { currentIndex++; if ( currentIndex > firstIndex ) ids.add( id ); if ( endIndex >= 0 && currentIndex >= endIndex ) break; } - + } return new PagedResult<String>(firstIndex, endIndex, criteria.getRestriction().toString(), null, ids ); } @@ -412,4 +417,4 @@ } } -} +} \ No newline at end of file Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/WikittyUtil.java 2009-11-04 10:18:51 UTC (rev 307) @@ -1,16 +1,16 @@ /* *##% * Copyright (c) 2009 poussin. All rights reserved. - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. *##%*/ @@ -53,7 +53,7 @@ public class WikittyUtil { public static final String DEFAULT_VERSION = "0.0"; - + /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(WikittyUtil.class); @@ -69,7 +69,7 @@ setTimeZone(CANONICAL_TZ); } } - + /** All date format parser used to convert string to date */ static final protected DateFormat[] parserDateFormats = new DateFormat[]{ solrDateFormat, @@ -533,8 +533,10 @@ * @param clazz class of the new instance * @param w wikitty object to use internaly for in new instance * @return + * @deprecated You should use <name>Impl.toBean() and new <name>Impl(Bean) */ // E extends BeanDto to permit business interface as parameter + @Deprecated static public <E extends BusinessEntity> E newInstance(Class<E> clazz, Wikitty w) { try { Class clazzInstanciable = clazz; @@ -744,10 +746,10 @@ byte[] b = new byte[16]; for ( int i = 0; i < 16; i++ ) { b[i] = (byte) (current & 0xff); - current = current >> 8; + current = current >> 8; if ( i == 7 ) current = leastSignificant; } return enc.encode(b); */ } -} +} \ No newline at end of file Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/AllTests.java 2009-11-04 10:18:51 UTC (rev 307) @@ -6,6 +6,7 @@ import org.sharengo.wikitty.test.api.CommonTest; import org.sharengo.wikitty.test.api.ExtensionFactoryTest; import org.sharengo.wikitty.test.api.SearchCriteriaTest; +import org.sharengo.wikitty.test.api.WikittyUtilTest; import org.sharengo.wikitty.test.conform.SearchApiTest; import org.sharengo.wikitty.test.conform.StorageTest; import org.sharengo.wikitty.test.memory.InMemoryStorageTest; @@ -18,6 +19,7 @@ CommonTest.class, ExtensionFactoryTest.class, SearchCriteriaTest.class, + WikittyUtilTest.class, /* * Conformance Tests */ Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/api/WikittyUtilTest.java 2009-11-04 10:18:51 UTC (rev 307) @@ -19,22 +19,15 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import java.math.BigDecimal; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; +import java.util.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.sharengo.wikitty.FieldType; -import org.sharengo.wikitty.Label; -import org.sharengo.wikitty.LabelImpl; -import org.sharengo.wikitty.TreeNodeBean; -import org.sharengo.wikitty.TreeNodeImpl; import org.sharengo.wikitty.WikittyExtension; import org.sharengo.wikitty.WikittyUtil; @@ -381,15 +374,13 @@ assertNotNull( ext.getFieldType("buildDate") ); } - // use in testNewInstance - static class MonLabel extends LabelImpl { - } /** * test newInstance method, and verify that we can configure implementation * for specifique interface * @throws Exception */ + /* Deprecated operation no more tested @Test public void testNewInstance() throws Exception { Label label = WikittyUtil.newInstance(Label.class, null); @@ -399,15 +390,6 @@ label = WikittyUtil.newInstance(Label.class, null); assertNull(label); } + */ - @Test - public void testConvert() throws Exception { - TreeNodeImpl impl = new TreeNodeImpl(); - impl.setName("toto"); - impl.setParent("idparent"); - - TreeNodeBean bean = WikittyUtil.wikittyToBean(TreeNodeBean.class, impl); - assertEquals(impl.getName(), bean.getName()); - assertEquals(impl.getParent(), bean.getParent()); - } } Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java 2009-11-04 10:15:49 UTC (rev 306) +++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/test/java/org/sharengo/wikitty/test/conform/StorageTest.java 2009-11-04 10:18:51 UTC (rev 307) @@ -413,7 +413,7 @@ } - + private void assign(Wikitty wikitty, TreeNodeImpl root, String path) { String[] nodeNames = path.split("/"); TreeNodeImpl currentNode = root;
participants (1)
-
kmorin@users.nuiton.org