├── .gitignore ├── LICENSE-2.0.txt ├── README.md ├── cache ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── cache │ │ ├── CacheAttributeExtractor.java │ │ ├── CacheConfig.java │ │ ├── CacheService.java │ │ ├── KeySelectionAdapter.java │ │ ├── SelectionAdapter.java │ │ ├── ValueSelectionAdapter.java │ │ └── ehcache │ │ ├── EhcacheAttributeExtractor.java │ │ ├── EhcacheKeySelectionAdapter.java │ │ ├── EhcacheSelectionAdapter.java │ │ ├── EhcacheService.java │ │ ├── EhcacheValueSelectionAdapter.java │ │ ├── ExtractorSupportedSearchAttribute.java │ │ ├── criteriahandlers │ │ ├── BasicCriteriaHandler.java │ │ ├── CriteriaHandler.java │ │ ├── EqualCriteria.java │ │ ├── InCriteria.java │ │ └── LogicalCriteria.java │ │ └── factory │ │ └── RepositoryFactory.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── datetime ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── cradle │ └── datetime │ ├── DateTimeOperation.java │ └── dateback │ ├── DateBackStrategy.java │ ├── DaysDateBackStrategy.java │ ├── HoursDateBackStrategy.java │ ├── MonthsDateBackStrategy.java │ ├── WeeksDateBackStrategy.java │ ├── WindowDateBackStrategy.java │ └── YearsDateBackStrategy.java ├── disruptor ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── disruptor │ │ ├── DisruptorEvent.java │ │ ├── DisruptorEventFactory.java │ │ ├── DisruptorEventHandler.java │ │ ├── DisruptorOperation.java │ │ ├── OnDataCallBack.java │ │ ├── RingBufferOperation.java │ │ └── workerpool │ │ ├── SimpleWorkEventHandler.java │ │ ├── WorkEvent.java │ │ ├── WorkEventHandler.java │ │ ├── WorkerPoolExceptionHandler.java │ │ ├── WorkerPoolOperation.java │ │ └── WorkerpoolTest.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ └── build.properties ├── keyspace_schema └── keyspace_schema.properties ├── localization ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── localization │ │ ├── LocalizationException.java │ │ ├── LocalizationService.java │ │ ├── Localized.java │ │ └── impl │ │ ├── LocalizationServiceImpl.java │ │ └── LocalizedIndexRowMapper.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── mail ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── mail │ │ ├── MailSendingException.java │ │ ├── MailService.java │ │ └── TLSMailService.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── oauth ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── oauth │ │ ├── HandshakeAdpater.java │ │ ├── NotHandshakingException.java │ │ ├── OAuthAuthorizer.java │ │ ├── OAuthBuilder.java │ │ ├── OAuthInvoker.java │ │ ├── OAuthProvider.java │ │ ├── OauthEntityNotFoundException.java │ │ ├── OauthInvokationException.java │ │ ├── OauthProviderNotSupported.java │ │ ├── google │ │ ├── Google2Api.java │ │ ├── GoogleOAuthBuilder.java │ │ ├── GoogleOAuthInvoker.java │ │ ├── GoogleOauthAuthorizer.java │ │ └── GoogleProfileInvoker.java │ │ └── impl │ │ └── OAuthProviderImpl.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── platform ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── platform │ │ ├── CradlePlatform.java │ │ ├── document │ │ ├── DocumentReader.java │ │ ├── DocumentReadingExcetion.java │ │ ├── DocumentWriter.java │ │ └── JsonDocumentReaderWriter.java │ │ ├── eventbus │ │ ├── CradleEventbus.java │ │ ├── EventbusListener.java │ │ └── spi │ │ │ ├── EventbusHandler.java │ │ │ ├── EventbusListenerRegistrationPrincipal.java │ │ │ └── TypeEventbusHandler.java │ │ ├── httpgateway │ │ ├── HttpAdapter.java │ │ ├── HttpFilter.java │ │ ├── HttpMethod.java │ │ ├── HttpWebService.java │ │ ├── client │ │ │ ├── AsynchronousReadingHttpClient.java │ │ │ ├── AsynchronousReadingWritingHttpClient.java │ │ │ ├── HttpDocumentResponseCallback.java │ │ │ └── HttpFileResponseCallback.java │ │ ├── exception │ │ │ ├── BadContentType.java │ │ │ ├── BadRequestException.java │ │ │ ├── ContentTypeNotSupported.java │ │ │ ├── HttpException.java │ │ │ ├── PathNotAccessibleException.java │ │ │ ├── RedirectException.java │ │ │ ├── UnauthorizedException.java │ │ │ └── UnknownResourceException.java │ │ ├── filter │ │ │ ├── Filter.java │ │ │ ├── FilterInvokationHandler.java │ │ │ ├── PrecedenceFilter.java │ │ │ ├── path │ │ │ │ └── PathFilter.java │ │ │ └── session │ │ │ │ └── SessionFilter.java │ │ └── spi │ │ │ ├── BasicHttpAdapter.java │ │ │ ├── GatewayRequest.java │ │ │ ├── GatewayResponse.java │ │ │ ├── OutputHttpHandler.java │ │ │ ├── ResponseObject.java │ │ │ ├── ServiceResponse.java │ │ │ ├── handler │ │ │ ├── AsyncIOtHttpHandler.java │ │ │ ├── AsyncInputHttpHandler.java │ │ │ ├── AsynchronusRequestHandler.java │ │ │ ├── BasicHttpHandler.java │ │ │ ├── MultipartIOHttpHandler.java │ │ │ └── MultipartRequestHandler.java │ │ │ └── registration │ │ │ ├── FilterRegistartionPrinicipal.java │ │ │ ├── HttpHandlerCreationStrategy.java │ │ │ └── HttpHandlerResgisterationPrinicipal.java │ │ ├── spi │ │ ├── BasicCradleProvider.java │ │ ├── CradleProvider.java │ │ ├── RegistrationAgent.java │ │ └── RegistrationPrincipal.java │ │ └── websocketgateway │ │ ├── WebSocket.java │ │ └── spi │ │ └── WebsocketHandlerRegistrationPrinicipal.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── reporting ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── reporting │ │ ├── BasicLoggingEvent.java │ │ ├── ExceptionLoggingEvent.java │ │ ├── InfoLoggingEvent.java │ │ ├── LoggingEvent.java │ │ ├── LoggingWorkHandler.java │ │ ├── SystemReportingService.java │ │ ├── SystemReportingServiceProxy.java │ │ ├── log4j │ │ └── Log4JSystemReportingService.java │ │ └── mail │ │ └── TLSMailSystemReportingService.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── repository ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── repository │ │ ├── BasicRowMapper.java │ │ ├── IndexRepository.java │ │ ├── ModelRepository.java │ │ ├── ModelRepositoryProxy.java │ │ ├── RowAdapter.java │ │ ├── StructuredRepository.java │ │ ├── UnknowRepositoryTargetException.java │ │ ├── cassandra │ │ ├── CassandraConfig.java │ │ ├── CassandraContext.java │ │ ├── CassandraRowAdapter.java │ │ ├── CassandraRowMapper.java │ │ ├── CassandraStructuredRepository.java │ │ ├── criteriahandlers │ │ │ ├── AndCriteria.java │ │ │ ├── BasicCriteriaHandler.java │ │ │ ├── BetweenCriteria.java │ │ │ ├── CriteriaHandler.java │ │ │ ├── EqualCriteria.java │ │ │ ├── InCriteria.java │ │ │ └── LeCriteria.java │ │ ├── mappers │ │ │ ├── AccountRowMapper.java │ │ │ ├── BasicCassandraMapper.java │ │ │ ├── ContentRowMapper.java │ │ │ ├── OauthRowMapper.java │ │ │ ├── ProfileRowMapper.java │ │ │ ├── RoleRowMapper.java │ │ │ └── TrackingLogRowMapper.java │ │ └── query │ │ │ └── CassandraSimpleSelectionAdapter.java │ │ ├── exception │ │ ├── ContentException.java │ │ └── NoResultException.java │ │ ├── index │ │ ├── Core.java │ │ ├── CoreAnnotationIsNotPresent.java │ │ ├── Index.java │ │ ├── IndexDocumentObjectFactory.java │ │ ├── IndexException.java │ │ ├── IndexId.java │ │ ├── IndexPorter.java │ │ ├── IndexQueryAdapter.java │ │ ├── QueryException.java │ │ ├── TargetHasNoIndexableFileds.java │ │ └── solrj │ │ │ ├── PortingCommand.java │ │ │ ├── SolrjIndexPorter.java │ │ │ ├── SolrjIndexRepository.java │ │ │ ├── SolrjQueryAdapter.java │ │ │ ├── SolrjRowAdapter.java │ │ │ └── SolrjRowMapper.java │ │ ├── key │ │ ├── RestCriteria.java │ │ ├── RestProjection.java │ │ ├── RestSearchKey.java │ │ ├── exception │ │ │ ├── BadCriteriaValueException.java │ │ │ ├── CriteriaNotFoundException.java │ │ │ ├── InvalidCriteriaException.java │ │ │ ├── InvalidCriteriaSyntaxException.java │ │ │ ├── InvalidKeyException.java │ │ │ ├── ServerFunctionException.java │ │ │ └── UnknowModelException.java │ │ ├── functions │ │ │ ├── BasicServerFunction.java │ │ │ ├── ServerFunctionHandler.java │ │ │ └── dateback │ │ │ │ ├── DateBack.java │ │ │ │ └── formatter │ │ │ │ ├── DateBackResultFormatter.java │ │ │ │ ├── ListDateBackResultFormatter.java │ │ │ │ └── OneItemDateBackResultFormatter.java │ │ ├── generator │ │ │ ├── KeyGenerator.java │ │ │ └── TemplateKeyGenerator.java │ │ └── parsers │ │ │ ├── GsonKeyParser.java │ │ │ └── KeyParser.java │ │ ├── models │ │ ├── RestModel.java │ │ ├── account │ │ │ ├── Account.java │ │ │ ├── Oauth.java │ │ │ ├── Profile.java │ │ │ └── Role.java │ │ ├── content │ │ │ └── Content.java │ │ └── tracking │ │ │ └── TrackingLog.java │ │ └── query │ │ ├── BasicSimpleSelectionAdapter.java │ │ ├── SimpleSelectionAdapter.java │ │ └── formatter │ │ └── QueryResultFormatter.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── schedule ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── schedule │ │ ├── JobBuildResult.java │ │ ├── JobBuilder.java │ │ ├── ScheduleContext.java │ │ ├── ScheduleService.java │ │ ├── ScheduledChainJob.java │ │ ├── ScheduledJob.java │ │ ├── ScheduledJobListener.java │ │ ├── SecondlyScheduledChainJob.java │ │ ├── exception │ │ └── ScheduleException.java │ │ ├── quartz │ │ ├── QuartzJob.java │ │ ├── QuartzJobBuilder.java │ │ ├── QuartzScheduleContext.java │ │ ├── QuartzScheduleService.java │ │ ├── QuartzScheduledJobListener.java │ │ └── builder │ │ │ ├── calendar │ │ │ ├── BasicCalendarBuilder.java │ │ │ ├── CalendarBuilder.java │ │ │ └── WeekCalendarBuilder.java │ │ │ └── schedule │ │ │ ├── BasicScheduleBuilder.java │ │ │ ├── DailyScheduleBuilder.java │ │ │ ├── QuartzScheduleBuilder.java │ │ │ ├── SecondlyScheduleBuilder.java │ │ │ └── WeeklyScheduleBuilder.java │ │ ├── session │ │ ├── ObservableScheduledSession.java │ │ ├── ScheduledSession.java │ │ ├── SessionException.java │ │ ├── SessionObserver.java │ │ ├── SessionStatus.java │ │ ├── SessionStatusCallback.java │ │ └── SessionTrackObserver.java │ │ └── tracks │ │ ├── DailyTrack.java │ │ ├── MinuteTrack.java │ │ ├── Track.java │ │ ├── TrackException.java │ │ └── WeeklyTrack.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties ├── security ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── cradle │ │ └── security │ │ ├── AuthenticationFailureException.java │ │ ├── SecurityService.java │ │ ├── User.java │ │ └── shiro │ │ ├── AccountAuthenticationInfo.java │ │ ├── AccountAuthorizationInfo.java │ │ ├── RepositoryRealm.java │ │ ├── ShiroSecurityService.java │ │ ├── ShiroUser.java │ │ └── SimpleSessionKey.java │ └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ └── build.properties └── vertx ├── .factorypath ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── cradle │ │ └── platform │ │ └── vertx │ │ ├── DeploymentReporter.java │ │ ├── HttpFilterAgent.java │ │ ├── VertxCradlePlatform.java │ │ ├── eventbus │ │ ├── VertxEventbusService.java │ │ └── VertxTextEventbusHandler.java │ │ ├── handlers │ │ ├── ContentRequestHandler.java │ │ ├── FileRequestHandler.java │ │ └── HttpInvokationHandler.java │ │ ├── httpgateway │ │ ├── AsyncInputStream.java │ │ ├── RemovableRouteMatcher.java │ │ ├── VertxAsynchronusRequest.java │ │ ├── VertxHttpAdapter.java │ │ ├── VertxHttpGateway.java │ │ └── client │ │ │ ├── DocumentRequestHandler.java │ │ │ ├── FileRequestHandler.java │ │ │ └── VertxReadingHttpClient.java │ │ └── websocketgateway │ │ ├── VertxWebsocketAdapter.java │ │ ├── VertxWebsocketGateway.java │ │ └── VertxWebsocketRequest.java └── resources │ ├── META-INF │ └── MANIFEST.MF │ ├── OSGI-INF │ └── blueprint │ │ └── config.xml │ ├── build.properties │ ├── html │ ├── webSocketMessage_Broadcast.html │ ├── webSocketMessage_Synchronous.html │ └── websocketMessage_Reciever.html │ └── js │ ├── jquery │ └── jquery-2.1.1.js │ └── sockjs │ └── sockjs-0.3.min.js └── test └── java └── org └── cradle └── gateway └── vertx └── test ├── Calculation.java ├── HelloWorldController.java ├── Message.java └── StandaloneGatewayTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /**/mods 2 | /**/zipfiles 3 | /**/logs 4 | /**/target 5 | /**/.metadata 6 | /**/.settings 7 | /**/.classpath 8 | /**/.project 9 | /**/bin 10 | /**/vertx_temp 11 | /**/*/*/data/index 12 | /**/*/*/data/tlog 13 | 14 | # Backup files 15 | *~ 16 | 17 | # IntelliJ IDEA 18 | /**/.idea/ 19 | /**/*.iml 20 | 21 | # Local log4j files (used to supply different logging parameters during development) 22 | log4j-local.properties 23 | -------------------------------------------------------------------------------- /cache/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/CacheAttributeExtractor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.cache; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 27, 2015 22 | */ 23 | public abstract class CacheAttributeExtractor { 24 | 25 | private String attributeName; 26 | 27 | public CacheAttributeExtractor(String attributeName) { 28 | 29 | this.attributeName = attributeName; 30 | } 31 | 32 | /** 33 | * @return the attributeName 34 | */ 35 | public String getAttributeName() { 36 | return attributeName; 37 | } 38 | 39 | public abstract Object extract(T cachedObject); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/KeySelectionAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.cache; 17 | 18 | 19 | /** 20 | * @author Sherief Shawky 21 | * @email mcrakens@gmail.com 22 | * @date Sep 2, 2014 23 | */ 24 | public interface KeySelectionAdapter extends SelectionAdapter { 25 | 26 | public SelectionAdapter eq(Object value); 27 | 28 | public SelectionAdapter like(Object value); 29 | 30 | public SelectionAdapter in(Object[] values); 31 | 32 | public SelectionAdapter orderBy(boolean asc); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/SelectionAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.cache; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 4, 2014 12 | */ 13 | public interface SelectionAdapter { 14 | 15 | public abstract SelectionAdapter page(int size); 16 | 17 | public abstract Map result(); 18 | 19 | } -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ValueSelectionAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.cache; 5 | 6 | 7 | /** 8 | * @author Sherief Shawky 9 | * @email mcrakens@gmail.com 10 | * @date Sep 3, 2014 11 | */ 12 | public interface ValueSelectionAdapter extends SelectionAdapter{ 13 | 14 | public ValueSelectionAdapter eq(String name, Object value); 15 | 16 | public ValueSelectionAdapter in(String name, Object[] values); 17 | 18 | public ValueSelectionAdapter orderBy(boolean asc, String name); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/EhcacheAttributeExtractor.java: -------------------------------------------------------------------------------- 1 | package org.cradle.cache.ehcache; 2 | 3 | import net.sf.ehcache.Element; 4 | import net.sf.ehcache.search.attribute.AttributeExtractor; 5 | import net.sf.ehcache.search.attribute.AttributeExtractorException; 6 | 7 | import org.cradle.cache.CacheAttributeExtractor; 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Jan 27, 2015 13 | */ 14 | public class EhcacheAttributeExtractor implements AttributeExtractor{ 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | private CacheAttributeExtractor attributeExtractor; 19 | 20 | public EhcacheAttributeExtractor(CacheAttributeExtractor attributeExtractor) { 21 | this.attributeExtractor = attributeExtractor; 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see net.sf.ehcache.search.attribute.AttributeExtractor#attributeFor(net.sf.ehcache.Element, java.lang.String) 26 | */ 27 | @SuppressWarnings("unchecked") 28 | @Override 29 | public Object attributeFor(Element element, String attributeName) 30 | throws AttributeExtractorException { 31 | 32 | T cachedObject = (T) element.getObjectValue(); 33 | 34 | return attributeExtractor.extract(cachedObject); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/EhcacheValueSelectionAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.cache.ehcache; 5 | 6 | import org.cradle.cache.ValueSelectionAdapter; 7 | 8 | import net.sf.ehcache.Cache; 9 | import net.sf.ehcache.search.Attribute; 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Sep 3, 2014 15 | */ 16 | public class EhcacheValueSelectionAdapter extends EhcacheSelectionAdapter implements ValueSelectionAdapter{ 17 | 18 | /** 19 | * @param cache 20 | */ 21 | public EhcacheValueSelectionAdapter(Cache cache) { 22 | super(cache); 23 | } 24 | 25 | 26 | 27 | /* (non-Javadoc) 28 | * @see org.cradle.cache.ValueSelectionAdapter#eq(java.lang.String, java.lang.Object) 29 | */ 30 | @Override 31 | public ValueSelectionAdapter eq(String name, Object value) { 32 | 33 | Attribute attr = getAttribute(name); 34 | 35 | doEq(value, attr); 36 | 37 | return this; 38 | } 39 | 40 | 41 | /* (non-Javadoc) 42 | * @see org.cradle.cache.ValueSelectionAdapter#in(java.lang.String, java.lang.Object[]) 43 | */ 44 | @Override 45 | public ValueSelectionAdapter in(String name, Object[] values) { 46 | 47 | Attribute attr = getAttribute(name); 48 | 49 | doIn(values, attr); 50 | 51 | return this; 52 | } 53 | 54 | 55 | /* (non-Javadoc) 56 | * @see org.cradle.cache.ValueSelectionAdapter#orderBy(boolean) 57 | */ 58 | @Override 59 | public ValueSelectionAdapter orderBy(boolean asc, String name) { 60 | 61 | Attribute attr = getAttribute(name); 62 | 63 | doOrderBy(asc, attr); 64 | 65 | return this; 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/ExtractorSupportedSearchAttribute.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.cache.ehcache; 17 | 18 | import net.sf.ehcache.config.SearchAttribute; 19 | import net.sf.ehcache.search.attribute.AttributeExtractor; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Jan 27, 2015 25 | */ 26 | public class ExtractorSupportedSearchAttribute extends SearchAttribute { 27 | 28 | private AttributeExtractor attributeExtractor; 29 | 30 | public ExtractorSupportedSearchAttribute( 31 | AttributeExtractor attributeExtractor) { 32 | 33 | this.attributeExtractor = attributeExtractor; 34 | } 35 | 36 | /* (non-Javadoc) 37 | * @see net.sf.ehcache.config.SearchAttribute#constructExtractor(java.lang.ClassLoader) 38 | */ 39 | @Override 40 | public AttributeExtractor constructExtractor(ClassLoader loader) { 41 | 42 | return attributeExtractor != null ? attributeExtractor : super.constructExtractor(loader); 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/criteriahandlers/BasicCriteriaHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.cache.ehcache.criteriahandlers; 5 | 6 | import java.util.Map; 7 | 8 | import net.sf.ehcache.Ehcache; 9 | import net.sf.ehcache.search.Attribute; 10 | import net.sf.ehcache.search.expression.Criteria; 11 | 12 | import org.cradle.repository.key.RestCriteria; 13 | import org.cradle.repository.key.exception.InvalidCriteriaException; 14 | 15 | /** 16 | * @author Sherief Shawky 17 | * @email mcrakens@gmail.com 18 | * @date Sep 4, 2014 19 | */ 20 | public abstract class BasicCriteriaHandler implements CriteriaHandler{ 21 | 22 | private Ehcache cache; 23 | 24 | /** 25 | * 26 | */ 27 | public BasicCriteriaHandler() { 28 | } 29 | 30 | @Override 31 | public void handle(RestCriteria criteria, Map criterias, Ehcache cache) 32 | throws InvalidCriteriaException { 33 | 34 | this.cache = cache; 35 | 36 | try { 37 | 38 | String id = criteria.readCriteriaId(); 39 | 40 | criterias.put(id, resolveCriteria(criteria, criterias)); 41 | 42 | } catch (Exception e) { 43 | 44 | throw new InvalidCriteriaException(e); 45 | } 46 | 47 | } 48 | 49 | protected Attribute getAttribute(String name) { 50 | 51 | return cache.getSearchAttribute(name); 52 | } 53 | 54 | protected abstract Criteria resolveCriteria(RestCriteria criteria, Map criterias) throws Exception; 55 | } -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/criteriahandlers/CriteriaHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.cache.ehcache.criteriahandlers; 5 | 6 | import java.util.Map; 7 | 8 | import net.sf.ehcache.Ehcache; 9 | import net.sf.ehcache.search.expression.Criteria; 10 | 11 | import org.cradle.repository.key.RestCriteria; 12 | import org.cradle.repository.key.exception.InvalidCriteriaException; 13 | 14 | /** 15 | * @author Sherief Shawky 16 | * @email mcrakens@gmail.com 17 | * @date Sep 4, 2014 18 | */ 19 | public interface CriteriaHandler { 20 | 21 | public void handle( 22 | RestCriteria criteria, 23 | Map criterias, 24 | Ehcache cache 25 | ) throws InvalidCriteriaException; 26 | } 27 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/criteriahandlers/EqualCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Sherief Shawky(raken123@yahoo.com) 3 | */ 4 | package org.cradle.cache.ehcache.criteriahandlers; 5 | 6 | import java.util.Map; 7 | 8 | import net.sf.ehcache.search.Attribute; 9 | import net.sf.ehcache.search.expression.Criteria; 10 | 11 | import org.cradle.repository.key.RestCriteria; 12 | 13 | 14 | /** 15 | * @author Sherief Shawky(raken123@yahoo.com) 16 | * 17 | */ 18 | public class EqualCriteria extends BasicCriteriaHandler { 19 | 20 | /* (non-Javadoc) 21 | * @see org.cradle.cache.ehcache.criteriahandlers.BasicCriteriaHandler#resolveCriteria(org.cradle.cache.key.RestCriteria, java.util.Map) 22 | */ 23 | @Override 24 | protected Criteria resolveCriteria( 25 | RestCriteria criteria, 26 | Map criterias) throws Exception { 27 | 28 | String name = criteria.readCriteriaName(); 29 | 30 | Attribute attr = getAttribute(name); 31 | 32 | return attr.eq(criteria.getParsedValue()); 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/criteriahandlers/InCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.cache.ehcache.criteriahandlers; 17 | 18 | import java.util.Arrays; 19 | import java.util.Map; 20 | 21 | import net.sf.ehcache.search.Attribute; 22 | import net.sf.ehcache.search.expression.Criteria; 23 | 24 | import org.cradle.repository.key.RestCriteria; 25 | 26 | /** 27 | * @author Sherief Shawky 28 | * @email mcrakens@gmail.com 29 | * @date Sep 4, 2014 30 | */ 31 | public class InCriteria extends BasicCriteriaHandler{ 32 | 33 | /* (non-Javadoc) 34 | * @see org.cradle.cache.ehcache.criteriahandlers.BasicCriteriaHandler#resolveCriteria(java.lang.String, org.cradle.cache.key.RestCriteria, java.util.Map) 35 | */ 36 | @Override 37 | protected Criteria resolveCriteria(RestCriteria criteria, 38 | Map criterias) throws Exception { 39 | 40 | String name = criteria.readCriteriaName(); 41 | 42 | Attribute attr = getAttribute(name); 43 | 44 | return attr.in(Arrays.asList(criteria.getParsedValues())); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /cache/src/main/java/org/cradle/cache/ehcache/factory/RepositoryFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.cache.ehcache.factory; 17 | 18 | import net.sf.ehcache.constructs.blocking.CacheEntryFactory; 19 | 20 | import org.cradle.repository.ModelRepository; 21 | import org.cradle.repository.key.RestSearchKey; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Nov 20, 2014 27 | */ 28 | public class RepositoryFactory implements CacheEntryFactory{ 29 | 30 | private ModelRepository repository; 31 | 32 | public RepositoryFactory(ModelRepository repository) { 33 | 34 | this.repository = repository; 35 | } 36 | 37 | 38 | /* (non-Javadoc) 39 | * @see net.sf.ehcache.constructs.blocking.CacheEntryFactory#createEntry(java.lang.Object) 40 | */ 41 | @Override 42 | public Object createEntry(Object key) throws Exception { 43 | 44 | return repository.read((RestSearchKey) key); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cache/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: cache 4 | Bundle-SymbolicName: cache 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /cache/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /datetime/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: datetime 4 | Bundle-SymbolicName: datetime 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /datetime/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/DateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.datetime.dateback; 5 | 6 | import org.cradle.datetime.DateTimeOperation; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 17, 2014 12 | */ 13 | public interface DateBackStrategy { 14 | 15 | public DateTimeOperation back(DateTimeOperation start, int amount); 16 | 17 | public DateTimeOperation shift(DateTimeOperation start); 18 | } 19 | -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/DaysDateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.datetime.dateback; 5 | 6 | import org.cradle.datetime.DateTimeOperation; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 17, 2014 12 | */ 13 | public class DaysDateBackStrategy implements DateBackStrategy { 14 | 15 | /* (non-Javadoc) 16 | * @see org.cradle.repository.key.functions.dateback.DateBackStrategy#substractDate(org.joda.time.DateTime, int) 17 | */ 18 | @Override 19 | public DateTimeOperation back(DateTimeOperation start, int amount) { 20 | 21 | return start.minusDays(amount); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.cradle.repository.key.functions.dateback.strategy.DateBackStrategy#shift(org.joda.time.DateTime) 26 | */ 27 | @Override 28 | public DateTimeOperation shift(DateTimeOperation start) { 29 | 30 | return start.startOfDay().startOfHour().startOfMinute().startOfSecond(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/HoursDateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.datetime.dateback; 17 | 18 | import org.cradle.datetime.DateTimeOperation; 19 | 20 | /** 21 | * @author Sherief Shawky 22 | * @email mcrakens@gmail.com 23 | * @date Sep 17, 2014 24 | */ 25 | public class HoursDateBackStrategy implements DateBackStrategy { 26 | 27 | /* (non-Javadoc) 28 | * @see org.cradle.repository.key.functions.dateback.DateBackStrategy#substractDate(org.joda.time.DateTime, int) 29 | */ 30 | @Override 31 | public DateTimeOperation back(DateTimeOperation start, int amount) { 32 | 33 | return start.minusHours(amount); 34 | } 35 | 36 | /* (non-Javadoc) 37 | * @see org.cradle.repository.key.functions.dateback.strategy.DateBackStrategy#shift(org.joda.time.DateTime) 38 | */ 39 | @Override 40 | public DateTimeOperation shift(DateTimeOperation start) { 41 | 42 | return start.startOfHour().startOfMinute().startOfSecond(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/MonthsDateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.datetime.dateback; 5 | 6 | import org.cradle.datetime.DateTimeOperation; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 17, 2014 12 | */ 13 | public class MonthsDateBackStrategy implements DateBackStrategy { 14 | 15 | /* (non-Javadoc) 16 | * @see org.cradle.repository.key.functions.dateback.DateBackStrategy#substractDate(org.joda.time.DateTime, int) 17 | */ 18 | @Override 19 | public DateTimeOperation back(DateTimeOperation start, int amount) { 20 | 21 | return start.minusMonths(amount); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.cradle.repository.key.functions.dateback.strategy.DateBackStrategy#shift(org.joda.time.DateTime) 26 | */ 27 | @Override 28 | public DateTimeOperation shift(DateTimeOperation start) { 29 | 30 | return start.startOfMonth().startOfDay().startOfHour().startOfMinute().startOfSecond(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/WeeksDateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.datetime.dateback; 5 | 6 | import org.cradle.datetime.DateTimeOperation; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 17, 2014 12 | */ 13 | public class WeeksDateBackStrategy implements DateBackStrategy{ 14 | 15 | /* (non-Javadoc) 16 | * @see org.cradle.repository.key.functions.dateback.DateBackStrategy#substractDate(org.joda.time.DateTime, int) 17 | */ 18 | @Override 19 | public DateTimeOperation back(DateTimeOperation start, int amount) { 20 | 21 | return start.minusWeeks(amount); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.cradle.repository.key.functions.dateback.strategy.DateBackStrategy#shift(org.cradle.datetime.DateTimeOperation) 26 | */ 27 | @Override 28 | public DateTimeOperation shift(DateTimeOperation start) { 29 | 30 | return start.startOfWeek().startOfDay().startOfHour().startOfMinute().startOfSecond(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/WindowDateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.datetime.dateback; 17 | 18 | import org.cradle.datetime.DateTimeOperation; 19 | 20 | /** 21 | * @author Sherief Shawky 22 | * @email mcrakens@gmail.com 23 | * @date Sep 17, 2014 24 | */ 25 | public class WindowDateBackStrategy implements DateBackStrategy { 26 | 27 | private int minutes; 28 | 29 | /** 30 | * 31 | */ 32 | public WindowDateBackStrategy() { 33 | } 34 | 35 | /** 36 | * 37 | */ 38 | public WindowDateBackStrategy(int minutes) { 39 | 40 | this.minutes = minutes; 41 | } 42 | 43 | /** 44 | * @param minutes the minutes to set 45 | */ 46 | public void setMinutes(int minutes) { 47 | this.minutes = minutes; 48 | } 49 | 50 | @Override 51 | public DateTimeOperation back(DateTimeOperation start, int amount) { 52 | 53 | return start.minusWindow(minutes, amount); 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see org.cradle.repository.key.functions.dateback.strategy.DateBackStrategy#shift(org.cradle.datetime.DateTimeOperation) 58 | */ 59 | @Override 60 | public DateTimeOperation shift(DateTimeOperation start) { 61 | 62 | return start.startOfWindow(minutes); 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /datetime/src/main/java/org/cradle/datetime/dateback/YearsDateBackStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.datetime.dateback; 5 | 6 | import org.cradle.datetime.DateTimeOperation; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 17, 2014 12 | */ 13 | public class YearsDateBackStrategy implements DateBackStrategy { 14 | 15 | /* (non-Javadoc) 16 | * @see org.cradle.repository.key.functions.dateback.DateBackStrategy#substractDate(org.joda.time.DateTime, int) 17 | */ 18 | @Override 19 | public DateTimeOperation back(DateTimeOperation start, int amount) { 20 | 21 | return start.minusYears(amount); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.cradle.repository.key.functions.dateback.strategy.DateBackStrategy#shift(org.cradle.datetime.DateTimeOperation) 26 | */ 27 | @Override 28 | public DateTimeOperation shift(DateTimeOperation start) { 29 | 30 | return start.startOfYear().startOfDay().startOfHour().startOfMinute().startOfSecond(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /disruptor/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /disruptor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | org.cradle 6 | cradle-disruptor 7 | 0.0.1-SNAPSHOT 8 | bundle 9 | 10 | 3.0 11 | UTF-8 12 | 13 | 14 | 15 | com.lmax 16 | disruptor 17 | 3.2.1 18 | 19 | 20 | 21 | 22 | 23 | org.apache.felix 24 | maven-bundle-plugin 25 | 2.3.4 26 | true 27 | true 28 | 29 | src/main/resources/META-INF 30 | true 31 | 32 | ${project.name} 33 | ${project.artifactId} 34 | org.cradle.disruptor, 35 | org.cradle.disruptor.workerpool 36 | 37 | 38 | 39 | 40 | maven-compiler-plugin 41 | ${maven.compiler.plugin.version} 42 | 43 | 1.7 44 | 1.7 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/DisruptorEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Jul 6, 2014 10 | */ 11 | public class DisruptorEvent { 12 | 13 | private T data; 14 | 15 | public T get(){ 16 | return data; 17 | } 18 | 19 | public void set(T data){ 20 | this.data = data; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/DisruptorEventFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor; 5 | 6 | import com.lmax.disruptor.EventFactory; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Jul 6, 2014 12 | */ 13 | public class DisruptorEventFactory implements EventFactory> { 14 | 15 | /* (non-Javadoc) 16 | * @see com.lmax.disruptor.EventFactory#newInstance() 17 | */ 18 | public DisruptorEvent newInstance() { 19 | return createInstance(); 20 | } 21 | 22 | protected DisruptorEvent createInstance(){ 23 | return new DisruptorEvent(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/DisruptorEventHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor; 5 | 6 | import com.lmax.disruptor.EventHandler; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Jul 6, 2014 12 | */ 13 | public abstract class DisruptorEventHandler implements EventHandler> { 14 | 15 | /* (non-Javadoc) 16 | * @see com.lmax.disruptor.EventHandler#onEvent(java.lang.Object, long, boolean) 17 | */ 18 | public void onEvent(DisruptorEvent event, long sequence, 19 | boolean endOfBatch) throws Exception { 20 | 21 | T data = event.get(); 22 | 23 | consume(data); 24 | 25 | } 26 | 27 | /** 28 | * @param data 29 | */ 30 | protected abstract void consume(T data); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/OnDataCallBack.java: -------------------------------------------------------------------------------- 1 | package org.cradle.disruptor; 2 | 3 | /** 4 | * Author: Sherief Shawky 5 | * Date: 7/9/2014. 6 | * Email: mcrakens@gmail.com 7 | */ 8 | public interface OnDataCallBack { 9 | 10 | public void onData(T data); 11 | } 12 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/RingBufferOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor; 5 | 6 | import com.lmax.disruptor.RingBuffer; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Oct 1, 2014 12 | * @param 13 | */ 14 | public class RingBufferOperation implements OnDataCallBack{ 15 | 16 | protected RingBuffer> ringBuffer; 17 | 18 | /** 19 | * 20 | */ 21 | public RingBufferOperation() { 22 | 23 | } 24 | 25 | @Override 26 | public void onData(T data) { 27 | 28 | long sequence = 0; 29 | 30 | try { 31 | 32 | sequence = ringBuffer.next(); // Grab the next sequence 33 | 34 | // Get the entry in the Disruptor 35 | // for the sequence 36 | DisruptorEvent event = ringBuffer.get(sequence); 37 | 38 | event.set(data); // Fill with data 39 | 40 | }finally{ 41 | 42 | ringBuffer.publish(sequence); 43 | } 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/workerpool/SimpleWorkEventHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.disruptor.workerpool; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 11, 2015 22 | */ 23 | public class SimpleWorkEventHandler extends WorkEventHandler{ 24 | 25 | /* (non-Javadoc) 26 | * @see org.cradle.disruptor.workerpool.WorkEventHandler#consume(java.lang.Object) 27 | */ 28 | @Override 29 | protected void consume(WorkEvent event) throws Exception { 30 | 31 | event.execute(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/workerpool/WorkEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.disruptor.workerpool; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 11, 2015 22 | */ 23 | public interface WorkEvent { 24 | public void execute(); 25 | } 26 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/workerpool/WorkEventHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor.workerpool; 5 | 6 | import org.cradle.disruptor.DisruptorEvent; 7 | 8 | import com.lmax.disruptor.WorkHandler; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @param 13 | * @email mcrakens@gmail.com 14 | * @date Oct 1, 2014 15 | */ 16 | public abstract class WorkEventHandler implements WorkHandler> { 17 | 18 | /* (non-Javadoc) 19 | * @see com.lmax.disruptor.WorkHandler#onEvent(java.lang.Object) 20 | */ 21 | @Override 22 | public void onEvent(DisruptorEvent event) throws Exception { 23 | 24 | T data = event.get(); 25 | 26 | consume(data); 27 | } 28 | 29 | protected abstract void consume(T data) throws Exception; 30 | } 31 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/workerpool/WorkerPoolExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor.workerpool; 5 | 6 | import com.lmax.disruptor.ExceptionHandler; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Oct 1, 2014 12 | */ 13 | public class WorkerPoolExceptionHandler implements ExceptionHandler { 14 | 15 | /* (non-Javadoc) 16 | * @see com.lmax.disruptor.ExceptionHandler#handleEventException(java.lang.Throwable, long, java.lang.Object) 17 | */ 18 | @Override 19 | public void handleEventException(Throwable ex, long sequence, Object event) { 20 | 21 | printException("Worker pool exception occured at sequence " + sequence, ex); 22 | 23 | } 24 | 25 | /* (non-Javadoc) 26 | * @see com.lmax.disruptor.ExceptionHandler#handleOnStartException(java.lang.Throwable) 27 | */ 28 | @Override 29 | public void handleOnStartException(Throwable ex) { 30 | printException("Worker pool start failure", ex); 31 | } 32 | 33 | /* (non-Javadoc) 34 | * @see com.lmax.disruptor.ExceptionHandler#handleOnShutdownException(java.lang.Throwable) 35 | */ 36 | @Override 37 | public void handleOnShutdownException(Throwable ex) { 38 | printException("Worker pool shutdown failure", ex); 39 | } 40 | 41 | private void printException(String message, Throwable e){ 42 | 43 | System.out.println(message); 44 | 45 | e.printStackTrace(); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/workerpool/WorkerPoolOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor.workerpool; 5 | 6 | import java.util.concurrent.Executor; 7 | import java.util.concurrent.Executors; 8 | 9 | import org.cradle.disruptor.DisruptorEvent; 10 | import org.cradle.disruptor.DisruptorEventFactory; 11 | import org.cradle.disruptor.RingBufferOperation; 12 | 13 | import com.lmax.disruptor.WorkerPool; 14 | 15 | 16 | /** 17 | * @author Sherief Shawky 18 | * @email mcrakens@gmail.com 19 | * @date Oct 1, 2014 20 | */ 21 | public class WorkerPoolOperation extends RingBufferOperation { 22 | 23 | private WorkerPool> workerPool; 24 | private DisruptorEventFactory factory; 25 | private WorkerPoolExceptionHandler exceptionHandler; 26 | 27 | @SuppressWarnings("unchecked") 28 | public WorkerPoolOperation(WorkEventHandler... workHandlers){ 29 | 30 | factory = new DisruptorEventFactory<>(); 31 | 32 | exceptionHandler = new WorkerPoolExceptionHandler(); 33 | 34 | workerPool = new WorkerPool>( 35 | factory, 36 | exceptionHandler, 37 | workHandlers); 38 | 39 | } 40 | 41 | public void start(){ 42 | 43 | Executor executor = Executors.newCachedThreadPool(); 44 | 45 | ringBuffer = workerPool.start(executor); 46 | } 47 | 48 | public void stop(){ 49 | 50 | workerPool.drainAndHalt(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /disruptor/src/main/java/org/cradle/disruptor/workerpool/WorkerpoolTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.disruptor.workerpool; 5 | 6 | import java.util.Random; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Oct 1, 2014 12 | */ 13 | public class WorkerpoolTest { 14 | 15 | public static class DemoEvent{ 16 | int id = new Random().nextInt(); 17 | } 18 | 19 | public static class DemoWorkEventHandler extends WorkEventHandler{ 20 | private int id = new Random().nextInt(); 21 | 22 | @Override 23 | protected void consume(DemoEvent data) throws InterruptedException { 24 | Thread.sleep(1000); 25 | System.out.println(id + " is consuming " + data.id); 26 | 27 | } 28 | 29 | } 30 | 31 | /** 32 | * @param args 33 | */ 34 | @SuppressWarnings("unchecked") 35 | public static void main(String[] args) { 36 | 37 | 38 | WorkerPoolOperation workerPoolOperation = 39 | new WorkerPoolOperation( 40 | new DemoWorkEventHandler(), 41 | new DemoWorkEventHandler(), 42 | new DemoWorkEventHandler(), 43 | new DemoWorkEventHandler(), 44 | new DemoWorkEventHandler() 45 | ); 46 | 47 | workerPoolOperation.start(); 48 | 49 | for(int i=0; i < 5; i++) 50 | workerPoolOperation.onData(new DemoEvent()); 51 | 52 | workerPoolOperation.stop(); 53 | 54 | System.out.println("Work done!"); 55 | 56 | System.out.println("+++++++++++++++++++++++++++++++++++"); 57 | 58 | workerPoolOperation.start(); 59 | 60 | for(int i=0; i < 5; i++) 61 | workerPoolOperation.onData(new DemoEvent()); 62 | 63 | workerPoolOperation.stop(); 64 | 65 | System.out.println("Work done!"); 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /disruptor/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: disruptor 4 | Bundle-SymbolicName: disruptor 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /disruptor/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /keyspace_schema/keyspace_schema.properties: -------------------------------------------------------------------------------- 1 | # Comma separated list of local cluster IPs. 2 | hosts= 3 | ### KEYSPACE 4 | keyspace_name=test 5 | keyspace=CREATE KEYSPACE test WITH REPLICATION \= { 'class' \: 'NetworkTopologyStrategy', '20' \: 3 }; 6 | core_host_connections=100 7 | core_host_simultaneous_connections=100 8 | max_host_connections=500 9 | max_host_simultaneous_connections=100 10 | ### TABLES 11 | #Comma separated list of table names. 12 | tables=trackinglog,account,role,profile,oauth,content 13 | content=CREATE TABLE content(id text, name text, type text, metainfo map, data blob, PRIMARY KEY ((id, name, type))); 14 | trackinglog=CREATE TABLE trackinglog(timing bigint, method text, resource_name text, resource_id list, user_id text, PRIMARY KEY (timing)); 15 | trackinglog_indices=CREATE INDEX on trackinglog (resource_name); 16 | profile=CREATE TABLE profile(email text, first_name text, last_name text, PRIMARY KEY (email)); 17 | oauth=CREATE TABLE oauth(email text, oauth_provider text, oauth_token text, secret text, raw_response text, last_access bigint, PRIMARY KEY ((email, oauth_provider))); 18 | account=CREATE TABLE account (email text , password text , roles list, PRIMARY KEY (email, password)); 19 | role=CREATE TABLE role (name text, permissions list, PRIMARY KEY (name)); 20 | -------------------------------------------------------------------------------- /localization/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /localization/src/main/java/org/cradle/localization/LocalizationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.localization; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 21, 2015 22 | */ 23 | public class LocalizationException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public LocalizationException(Throwable e) { 34 | super("Error in localization operation", e); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /localization/src/main/java/org/cradle/localization/LocalizationService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.localization; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author Sherief Shawky 22 | * @email mcrakens@gmail.com 23 | * @date Jan 21, 2015 24 | */ 25 | public interface LocalizationService { 26 | 27 | public List localize(String language, List ids) throws LocalizationException; 28 | } 29 | -------------------------------------------------------------------------------- /localization/src/main/java/org/cradle/localization/Localized.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.localization; 17 | 18 | import org.cradle.repository.index.Core; 19 | import org.cradle.repository.index.Index; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Jan 21, 2015 25 | */ 26 | @Core("localized") 27 | public class Localized { 28 | 29 | @Index 30 | private String id; 31 | 32 | @Index 33 | private String language; 34 | 35 | @Index 36 | private String desc; 37 | 38 | public Localized(String id, String language, String desc) { 39 | this.id = id; 40 | this.language = language; 41 | this.desc = desc; 42 | } 43 | 44 | public String getId() { 45 | return id; 46 | } 47 | 48 | public String getLanguage() { 49 | return language; 50 | } 51 | 52 | public String getDesc() { 53 | return desc; 54 | } 55 | 56 | /** 57 | * @param language the language to set 58 | */ 59 | public void setLanguage(String language) { 60 | this.language = language; 61 | } 62 | 63 | /** 64 | * @param id the id to set 65 | */ 66 | public void setId(String id) { 67 | this.id = id; 68 | } 69 | 70 | /** 71 | * @param desc the desc to set 72 | */ 73 | public void setDesc(String desc) { 74 | this.desc = desc; 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /localization/src/main/java/org/cradle/localization/impl/LocalizedIndexRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.localization.impl; 17 | 18 | import org.cradle.localization.Localized; 19 | import org.cradle.repository.BasicRowMapper; 20 | import org.cradle.repository.RowAdapter; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Jan 28, 2015 26 | */ 27 | public class LocalizedIndexRowMapper extends BasicRowMapper { 28 | 29 | @Override 30 | public Localized map(RowAdapter row) { 31 | 32 | return new Localized( 33 | row.getString("id"), 34 | row.getString("language"), 35 | row.getString("language") 36 | ); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /localization/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: localization 4 | Bundle-SymbolicName: localization 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /localization/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /mail/src/main/java/org/cradle/mail/MailSendingException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.mail; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 28, 2014 10 | */ 11 | public class MailSendingException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | public MailSendingException(Throwable e){ 19 | super("Error occured while sending mail.", e); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /mail/src/main/java/org/cradle/mail/MailService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.mail; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 28, 2014 10 | */ 11 | public interface MailService { 12 | 13 | public void sendMail(String to, String subject, String body) throws MailSendingException; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /mail/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: mail 4 | Bundle-SymbolicName: mail 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /mail/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /mail/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /oauth/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/HandshakeAdpater.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 15, 2015 22 | */ 23 | public interface HandshakeAdpater { 24 | 25 | public String readParameter(String name); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/NotHandshakingException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 15, 2015 22 | */ 23 | public class NotHandshakingException extends Throwable { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public NotHandshakingException() { 34 | 35 | super("This user has not started handshaking operation"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/OAuthAuthorizer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | import org.cradle.repository.models.account.Oauth; 19 | import org.scribe.model.Token; 20 | import org.scribe.oauth.OAuthService; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Jan 18, 2015 26 | */ 27 | public abstract class OAuthAuthorizer { 28 | 29 | protected OAuthService service; 30 | protected String provider; 31 | 32 | public OAuthAuthorizer(OAuthService service, 33 | String provider) { 34 | 35 | this.service = service; 36 | this.provider = provider; 37 | } 38 | 39 | public Oauth finish(HandshakeAdpater handshakeAdpater){ 40 | 41 | Token accessToken = createAccessToken(handshakeAdpater, service); 42 | 43 | return new Oauth(provider, accessToken.getToken(), accessToken.getSecret(), accessToken.getRawResponse()); 44 | 45 | } 46 | 47 | public abstract String start(); 48 | 49 | protected abstract Token createAccessToken(HandshakeAdpater handshakeAdpater, OAuthService service); 50 | } 51 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/OAuthBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | import org.cradle.repository.models.account.Oauth; 19 | import org.cradle.repository.models.account.Profile; 20 | 21 | 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Dec 22, 2014 27 | */ 28 | public interface OAuthBuilder { 29 | 30 | public OAuthAuthorizer buildAuthorizer(); 31 | 32 | public OAuthInvoker buildProfileInvoker(Oauth oauth); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/OAuthProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | import org.cradle.repository.models.account.Oauth; 19 | import org.cradle.repository.models.account.Profile; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Jan 19, 2015 25 | */ 26 | public interface OAuthProvider { 27 | 28 | public OAuthAuthorizer authorizer(String provider) throws OauthProviderNotSupported; 29 | 30 | public OAuthInvoker profile(String provider, Oauth oauth) throws OauthProviderNotSupported; 31 | } 32 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/OauthEntityNotFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 18, 2015 22 | */ 23 | public class OauthEntityNotFoundException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public OauthEntityNotFoundException(String email, String provider) { 34 | super("No oauth entity found related to: " + email + " using provider: " + provider); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/OauthInvokationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 15, 2015 22 | */ 23 | public class OauthInvokationException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public OauthInvokationException() { 34 | super("Handshake failed"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /oauth/src/main/java/org/cradle/oauth/OauthProviderNotSupported.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.oauth; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 18, 2015 22 | */ 23 | public class OauthProviderNotSupported extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public OauthProviderNotSupported(String provider) { 34 | super("Oauth provider " + provider + " not found"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /oauth/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: oauth 4 | Bundle-SymbolicName: oauth 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /oauth/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /oauth/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /platform/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/CradlePlatform.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform; 17 | 18 | import org.cradle.platform.eventbus.CradleEventbus; 19 | import org.cradle.platform.spi.CradleProvider; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Apr 16, 2015 25 | */ 26 | public interface CradlePlatform { 27 | 28 | public void shutdown(); 29 | 30 | public CradleProvider httpGateway(); 31 | 32 | public CradleProvider httpGateway(String host, int port, String fileRoot, String webRoot); 33 | 34 | public CradleEventbus eventbus(); 35 | 36 | public CradleProvider websocketGateway(); 37 | } 38 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/document/DocumentReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.document; 5 | 6 | import java.nio.ByteBuffer; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Aug 11, 2014 12 | */ 13 | public interface DocumentReader { 14 | 15 | public Object read(Class documentType, ByteBuffer buffer) throws DocumentReadingExcetion; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/document/DocumentReadingExcetion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.document; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Nov 6, 2014 10 | */ 11 | public class DocumentReadingExcetion extends Exception { 12 | 13 | private String contentType; 14 | 15 | 16 | /** 17 | * @param contentType 18 | */ 19 | public DocumentReadingExcetion(String contentType) { 20 | this.contentType = contentType; 21 | } 22 | 23 | /** 24 | * @return the contentType 25 | */ 26 | public String getContentType() { 27 | return contentType; 28 | } 29 | 30 | /** 31 | * 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * 37 | */ 38 | public DocumentReadingExcetion(Throwable e) { 39 | super("Failed to read document", e); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/document/DocumentWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.document; 5 | 6 | import java.nio.ByteBuffer; 7 | /** 8 | * @author Sherief Shawky 9 | * @email mcrakens@gmail.com 10 | * @date Aug 11, 2014 11 | */ 12 | public interface DocumentWriter { 13 | 14 | /** 15 | * @param document 16 | * @param output 17 | */ 18 | public void write(Object document, ByteBuffer output); 19 | 20 | public void write(Object document, StringBuffer buffer); 21 | } 22 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/eventbus/CradleEventbus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.eventbus; 5 | 6 | import org.cradle.platform.spi.CradleProvider; 7 | 8 | 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Aug 14, 2014 14 | */ 15 | public interface CradleEventbus extends CradleProvider{ 16 | 17 | public void publish(String address, String message); 18 | 19 | public void publish(String address, T message, String contentType); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/eventbus/EventbusListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.eventbus; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Apr 27, 2015 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.METHOD) 30 | public @interface EventbusListener { 31 | String path(); 32 | } 33 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/eventbus/spi/EventbusHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.eventbus.spi; 17 | 18 | 19 | 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Apr 16, 2015 25 | */ 26 | public interface EventbusHandler { 27 | 28 | public void recieve(String message); 29 | 30 | } -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/eventbus/spi/TypeEventbusHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.eventbus.spi; 17 | 18 | import com.google.gson.Gson; 19 | import com.google.gson.GsonBuilder; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Apr 16, 2015 25 | */ 26 | public abstract class TypeEventbusHandler implements EventbusHandler{ 27 | 28 | private Gson gson; 29 | private Class messageType; 30 | /** 31 | * 32 | */ 33 | public TypeEventbusHandler(Class messageType) { 34 | 35 | gson = new GsonBuilder().create(); 36 | 37 | this.messageType = messageType; 38 | } 39 | 40 | private Object unmarshall(String message){ 41 | 42 | return gson.fromJson(message, messageType); 43 | } 44 | 45 | @Override 46 | public void recieve(String message){ 47 | 48 | recieve(unmarshall(message)); 49 | } 50 | 51 | protected abstract void recieve(T message); 52 | 53 | } -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/HttpFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Apr 22, 2015 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.METHOD) 30 | public @interface HttpFilter { 31 | String pattern(); 32 | int precedence() default 0; 33 | } 34 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Apr 16, 2015 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.METHOD) 30 | public @interface HttpMethod { 31 | 32 | enum Method{ 33 | 34 | GET("GET"), POST("POST"), MULTIPART_POST("POST"), PUT("PUT"), DELETE("DELETE"); 35 | 36 | private String value; 37 | 38 | private Method(String value){ 39 | this.value = value; 40 | } 41 | 42 | /** 43 | * @return the value 44 | */ 45 | public String getValue() { 46 | return value; 47 | } 48 | }; 49 | 50 | Method method(); 51 | String path(); 52 | String contentType() default "application/json"; 53 | } 54 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/HttpWebService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway; 5 | 6 | import org.cradle.platform.httpgateway.client.AsynchronousReadingHttpClient; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Oct 8, 2014 12 | */ 13 | public interface HttpWebService { 14 | 15 | public AsynchronousReadingHttpClient createReadingHttpClient(); 16 | } 17 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/client/AsynchronousReadingHttpClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.client; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Aug 27, 2014 12 | */ 13 | public interface AsynchronousReadingHttpClient { 14 | 15 | public void configure(String host, int port, int poolSize); 16 | 17 | 18 | public void read( 19 | String uri, 20 | String documentType, 21 | Class documentClass, 22 | HttpDocumentResponseCallback callback 23 | ); 24 | 25 | public void read( 26 | String uri, 27 | Map headers, 28 | String documentType, 29 | Class documentClass, 30 | HttpDocumentResponseCallback callback 31 | ); 32 | 33 | public void download(String uri, String name, HttpFileResponseCallback callback); 34 | } 35 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/client/AsynchronousReadingWritingHttpClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.client; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Aug 27, 2014 12 | */ 13 | public interface AsynchronousReadingWritingHttpClient extends AsynchronousReadingHttpClient{ 14 | 15 | public void create( 16 | String uri, 17 | Map headers, 18 | String documentType, 19 | Object input, 20 | HttpDocumentResponseCallback callback 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/client/HttpDocumentResponseCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.client; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 27, 2014 10 | */ 11 | public interface HttpDocumentResponseCallback { 12 | 13 | public void response(Object result); 14 | 15 | public void error(Throwable e); 16 | } 17 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/client/HttpFileResponseCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.client; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Nov 12, 2014 12 | */ 13 | public interface HttpFileResponseCallback { 14 | 15 | public void response(File result); 16 | 17 | public void error(Throwable e); 18 | } 19 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/BadContentType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 27, 2014 10 | */ 11 | public class BadContentType extends Throwable { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public BadContentType() { 22 | super("Missing or bad contentType"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/BadRequestException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 26, 2014 10 | */ 11 | public class BadRequestException extends HttpException{ 12 | 13 | /** 14 | * @param e 15 | */ 16 | public BadRequestException(Throwable e) { 17 | super("Bad request", e); 18 | } 19 | 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 1L; 24 | 25 | /* (non-Javadoc) 26 | * @see org.cradle.gateway.restful.exception.RESTfulException#getErrorCode() 27 | */ 28 | @Override 29 | public int getErrorCode() { 30 | return 400; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/ContentTypeNotSupported.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 27, 2014 10 | */ 11 | public class ContentTypeNotSupported extends Throwable { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public ContentTypeNotSupported(String contentType) { 22 | super("Content type " + contentType + " is not supported"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/HttpException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway.exception; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Aug 26, 2014 22 | */ 23 | public abstract class HttpException extends Exception{ 24 | 25 | /** 26 | * 27 | */ 28 | public HttpException(String msg, Throwable e) { 29 | super(msg, e); 30 | } 31 | 32 | /** 33 | * 34 | */ 35 | private static final long serialVersionUID = 1L; 36 | 37 | public abstract int getErrorCode(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/PathNotAccessibleException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Nov 10, 2014 10 | */ 11 | public class PathNotAccessibleException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public PathNotAccessibleException(String path, String method) { 22 | super(path + " is not accessible using: " + method + " for this user."); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/RedirectException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway.exception; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 20, 2015 22 | */ 23 | public class RedirectException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | private String url; 31 | 32 | /** 33 | * 34 | */ 35 | public RedirectException(String url) { 36 | 37 | super("Redirect required"); 38 | 39 | this.url = url; 40 | } 41 | 42 | /** 43 | * @return the url 44 | */ 45 | public String getUrl() { 46 | return url; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 26, 2014 10 | */ 11 | public class UnauthorizedException extends HttpException { 12 | 13 | /** 14 | * @param e 15 | */ 16 | public UnauthorizedException(Throwable e) { 17 | super("Unauthorized operation detected", e); 18 | } 19 | 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 1L; 24 | 25 | /* (non-Javadoc) 26 | * @see org.cradle.gateway.restful.exception.RESTfulException#getErrorCode() 27 | */ 28 | @Override 29 | public int getErrorCode() { 30 | return 401; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/exception/UnknownResourceException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway.exception; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 6, 2015 22 | */ 23 | public class UnknownResourceException extends HttpException{ 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public UnknownResourceException(Throwable e) { 34 | 35 | super("Unknown resource exception.", e); 36 | } 37 | 38 | /* (non-Javadoc) 39 | * @see org.cradle.gateway.restful.exception.RESTfulException#getErrorCode() 40 | */ 41 | @Override 42 | public int getErrorCode() { 43 | 44 | return 404; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/filter/Filter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.filter; 5 | 6 | import org.cradle.platform.httpgateway.HttpAdapter; 7 | import org.cradle.platform.httpgateway.exception.HttpException; 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Aug 25, 2014 13 | */ 14 | public interface Filter { 15 | 16 | public void filter(HttpAdapter httpAdapter) throws HttpException; 17 | 18 | } -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/filter/PrecedenceFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway.filter; 17 | 18 | 19 | /** 20 | * @author Sherief Shawky 21 | * @email mcrakens@gmail.com 22 | * @date Apr 26, 2015 23 | */ 24 | public abstract class PrecedenceFilter implements Filter { 25 | 26 | private int precedence; 27 | 28 | /** 29 | * @param precedence 30 | */ 31 | public PrecedenceFilter(int precedence) { 32 | this.precedence = precedence; 33 | } 34 | 35 | public int compare(PrecedenceFilter filter){ 36 | 37 | if(precedence < filter.precedence){ 38 | return -1; 39 | } else if(precedence == filter.precedence){ 40 | return 0; 41 | } else { 42 | return 1; 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/filter/path/PathFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.filter.path; 5 | 6 | import org.cradle.platform.httpgateway.HttpAdapter; 7 | import org.cradle.platform.httpgateway.exception.BadRequestException; 8 | import org.cradle.platform.httpgateway.exception.PathNotAccessibleException; 9 | import org.cradle.platform.httpgateway.exception.UnauthorizedException; 10 | import org.cradle.platform.httpgateway.filter.Filter; 11 | 12 | /** 13 | * @author Sherief Shawky 14 | * @email mcrakens@gmail.com 15 | * @date Nov 10, 2014 16 | */ 17 | public class PathFilter implements Filter { 18 | 19 | /* (non-Javadoc) 20 | * @see org.cradle.gateway.restful.filter.BasicRESTfulFilter#doFilter(org.cradle.gateway.HttpAdapter) 21 | */ 22 | @Override 23 | public void filter(HttpAdapter httpAdapter) 24 | throws BadRequestException, UnauthorizedException { 25 | 26 | try { 27 | 28 | httpAdapter.isPathAccessible(); 29 | 30 | } catch (PathNotAccessibleException e) { 31 | 32 | throw new UnauthorizedException(e); 33 | } 34 | 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/filter/session/SessionFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.filter.session; 5 | 6 | import org.cradle.platform.httpgateway.HttpAdapter; 7 | import org.cradle.platform.httpgateway.exception.BadRequestException; 8 | import org.cradle.platform.httpgateway.exception.UnauthorizedException; 9 | import org.cradle.platform.httpgateway.filter.Filter; 10 | import org.cradle.security.SecurityService; 11 | import org.cradle.security.User; 12 | 13 | /** 14 | * @author Sherief Shawky 15 | * @email mcrakens@gmail.com 16 | * @date Nov 9, 2014 17 | */ 18 | public class SessionFilter implements Filter { 19 | 20 | private SecurityService securityService; 21 | 22 | public SessionFilter(SecurityService securityService) { 23 | this.securityService = securityService; 24 | } 25 | 26 | /* (non-Javadoc) 27 | * @see org.cradle.gateway.restful.filter.RESTfulFilter#filter(org.cradle.gateway.HttpAdapter) 28 | */ 29 | @Override 30 | public void filter(HttpAdapter httpAdapter) throws BadRequestException, 31 | UnauthorizedException { 32 | 33 | String sessionId = httpAdapter.sessionId(); 34 | 35 | User user = securityService.identify(sessionId); 36 | 37 | httpAdapter.setUser(user); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/spi/handler/AsynchronusRequestHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.httpgateway.spi.handler; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Aug 14, 2014 10 | */ 11 | public interface AsynchronusRequestHandler { 12 | 13 | public void handleDocument(Object document); 14 | } 15 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/spi/handler/MultipartRequestHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway.spi.handler; 17 | 18 | import java.io.File; 19 | import java.util.List; 20 | 21 | import org.cradle.platform.httpgateway.HttpAdapter; 22 | import org.cradle.platform.httpgateway.spi.GatewayRequest; 23 | import org.cradle.platform.httpgateway.spi.GatewayResponse; 24 | 25 | /** 26 | * @author Sherief Shawky 27 | * @email mcrakens@gmail.com 28 | * @date Jan 4, 2015 29 | */ 30 | public interface MultipartRequestHandler { 31 | 32 | public Object createFormInstance(); 33 | 34 | public void handle(HttpAdapter httpAdapter, GatewayRequest request, GatewayResponse response, Object form, List uploads); 35 | } 36 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/httpgateway/spi/registration/HttpHandlerCreationStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.httpgateway.spi.registration; 17 | 18 | import java.lang.annotation.Annotation; 19 | import java.lang.reflect.Method; 20 | 21 | import org.cradle.platform.httpgateway.HttpMethod; 22 | import org.cradle.platform.httpgateway.spi.handler.BasicHttpHandler; 23 | 24 | /** 25 | * @author Sherief Shawky 26 | * @email mcrakens@gmail.com 27 | * @date Apr 27, 2015 28 | */ 29 | public interface HttpHandlerCreationStrategy { 30 | 31 | public BasicHttpHandler createHttpHandler(final Object handler, final Method target, final HttpMethod annotation); 32 | 33 | public void isMethodValid(Method target, Annotation annotation); 34 | } 35 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/spi/BasicCradleProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.spi; 17 | 18 | import static com.google.common.base.Preconditions.checkNotNull; 19 | 20 | import java.lang.reflect.Method; 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Apr 15, 2015 25 | */ 26 | public class BasicCradleProvider implements CradleProvider{ 27 | 28 | protected RegistrationPrincipal[] principals; 29 | 30 | /* (non-Javadoc) 31 | * @see org.cradle.platform.spi.CradleProvider#registerController(java.lang.Object) 32 | */ 33 | @Override 34 | public void registerController(T receiver) { 35 | 36 | checkNotNull(receiver); 37 | 38 | checkNotNull(principals); 39 | 40 | for (Method method : receiver.getClass().getMethods()) 41 | { 42 | for(RegistrationPrincipal principal : principals){ 43 | 44 | principal.execute(receiver, method); 45 | } 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/spi/CradleProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.spi; 17 | 18 | 19 | /** 20 | * @author Sherief Shawky 21 | * @email mcrakens@gmail.com 22 | * @date Aug 5, 2014 23 | */ 24 | public interface CradleProvider { 25 | 26 | public void registerController(T handler); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/spi/RegistrationAgent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.spi; 17 | 18 | import java.lang.annotation.Annotation; 19 | 20 | /** 21 | * @author Sherief Shawky 22 | * @email mcrakens@gmail.com 23 | * @date Apr 15, 2015 24 | */ 25 | public interface RegistrationAgent { 26 | 27 | public void register(A annotation, T handler); 28 | } 29 | -------------------------------------------------------------------------------- /platform/src/main/java/org/cradle/platform/websocketgateway/WebSocket.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.websocketgateway; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Apr 19, 2015 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.METHOD) 30 | public @interface WebSocket { 31 | 32 | enum Type{ 33 | RECEIVER(), SYNCHRONOUS(), BROADCAST(); 34 | private Type(){ 35 | } 36 | }; 37 | 38 | Type type(); 39 | String path(); 40 | String contentType() default "application/json"; 41 | } 42 | -------------------------------------------------------------------------------- /platform/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: platform 4 | Bundle-SymbolicName: platform 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /platform/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /platform/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /reporting/src/main/java/org/cradle/reporting/BasicLoggingEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.reporting; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 3, 2014 10 | */ 11 | public abstract class BasicLoggingEvent implements LoggingEvent { 12 | 13 | protected String reporter; 14 | protected String channel; 15 | protected SystemReportingService reportingService; 16 | 17 | public BasicLoggingEvent(String reporter, String channel, 18 | SystemReportingService reportingService) { 19 | this.reporter = reporter; 20 | this.channel = channel; 21 | this.reportingService = reportingService; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /reporting/src/main/java/org/cradle/reporting/ExceptionLoggingEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.reporting; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 3, 2014 10 | */ 11 | public class ExceptionLoggingEvent extends BasicLoggingEvent { 12 | 13 | private Throwable error; 14 | 15 | public ExceptionLoggingEvent(String reporter, String channel, 16 | SystemReportingService reportingService, Throwable error) { 17 | 18 | super(reporter, channel, reportingService); 19 | 20 | this.error = error; 21 | } 22 | 23 | /* (non-Javadoc) 24 | * @see org.cradle.system.reporting.LoggingEvent#execute() 25 | */ 26 | @Override 27 | public void execute() { 28 | 29 | reportingService.exception(reporter, channel, error); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /reporting/src/main/java/org/cradle/reporting/InfoLoggingEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.reporting; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 3, 2014 10 | */ 11 | public class InfoLoggingEvent extends BasicLoggingEvent { 12 | 13 | private String message; 14 | 15 | public InfoLoggingEvent(String reporter, String channel, 16 | SystemReportingService reportingService, String message) { 17 | 18 | super(reporter, channel, reportingService); 19 | 20 | this.message = message; 21 | } 22 | 23 | /* (non-Javadoc) 24 | * @see org.cradle.system.reporting.LoggingEvent#execute() 25 | */ 26 | @Override 27 | public void execute() { 28 | reportingService.info(reporter, channel, message); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /reporting/src/main/java/org/cradle/reporting/LoggingEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.reporting; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 3, 2014 10 | */ 11 | public interface LoggingEvent { 12 | 13 | public void execute(); 14 | } 15 | -------------------------------------------------------------------------------- /reporting/src/main/java/org/cradle/reporting/LoggingWorkHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.reporting; 5 | 6 | import org.cradle.disruptor.workerpool.WorkEventHandler; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Oct 3, 2014 12 | */ 13 | public class LoggingWorkHandler extends WorkEventHandler { 14 | 15 | /* (non-Javadoc) 16 | * @see org.cradle.disruptor.workerpool.WorkEventHandler#consume(java.lang.Object) 17 | */ 18 | @Override 19 | protected void consume(LoggingEvent data) throws Exception { 20 | data.execute(); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /reporting/src/main/java/org/cradle/reporting/SystemReportingService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.reporting; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 2, 2014 10 | */ 11 | public interface SystemReportingService { 12 | 13 | public static final String CONSOLE = "console"; 14 | public static final String FILE = "file"; 15 | public static final String MAIL = "mail"; 16 | 17 | public void info(String reporter, String channel, String message); 18 | 19 | public void exception(String reporter, String channel, Throwable ex); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /reporting/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: reporting 4 | Bundle-SymbolicName: reporting 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /reporting/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/BasicRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository; 17 | 18 | 19 | /** 20 | * @author Sherief Shawky 21 | * @email mcrakens@gmail.com 22 | * @date Jan 26, 2015 23 | */ 24 | public abstract class BasicRowMapper { 25 | 26 | private ModelRepository repository; 27 | private String modelName; 28 | private String target; 29 | 30 | /** 31 | * @param target the target to set 32 | */ 33 | public void setTarget(String target) { 34 | this.target = target; 35 | } 36 | 37 | public void setRepository(ModelRepository repository) { 38 | this.repository = repository; 39 | } 40 | 41 | public void setModelName(String modelName) { 42 | this.modelName = modelName; 43 | } 44 | 45 | public void init() throws UnknowRepositoryTargetException{ 46 | 47 | repository.registerMapper(target, modelName, this); 48 | } 49 | 50 | public abstract T map(RowAdapter row); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/IndexRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository; 5 | 6 | import java.util.List; 7 | 8 | import org.cradle.repository.index.CoreAnnotationIsNotPresent; 9 | import org.cradle.repository.index.IndexException; 10 | import org.cradle.repository.index.IndexPorter; 11 | import org.cradle.repository.index.IndexQueryAdapter; 12 | import org.cradle.repository.key.RestSearchKey; 13 | 14 | /** 15 | * @author Sherief Shawky 16 | * @email mcrakens@gmail.com 17 | * @date Nov 19, 2014 18 | */ 19 | public interface IndexRepository { 20 | 21 | public enum CoreLanguage { 22 | 23 | ENGLISH("en"), ARABIC("ar"); 24 | 25 | public String value; 26 | 27 | CoreLanguage(String value){ 28 | this.value = value; 29 | } 30 | } 31 | 32 | public List readIndex(RestSearchKey key) throws IndexException; 33 | 34 | public void writeIndex(T model) throws IndexException; 35 | 36 | public void writeIndex(List models) throws IndexException; 37 | 38 | public void deleteIndex(T model) throws IndexException; 39 | 40 | public void deleteIndex(List model) throws IndexException; 41 | 42 | public IndexPorter indexPorter(Class type) throws CoreAnnotationIsNotPresent; 43 | 44 | public IndexPorter indexPorter(Class type, CoreLanguage language) throws CoreAnnotationIsNotPresent; 45 | 46 | public IndexQueryAdapter queryAdapter(String coreName); 47 | 48 | public void registerIndexMapper(String modelName, BasicRowMapper mapper); 49 | } -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/ModelRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository; 17 | 18 | import java.io.File; 19 | 20 | import org.cradle.repository.exception.ContentException; 21 | import org.cradle.repository.models.content.Content; 22 | 23 | 24 | 25 | /** 26 | * @author Sherief Shawky 27 | * @email mcrakens@gmail.com 28 | * @date Jul 14, 2014 29 | */ 30 | public interface ModelRepository extends StructuredRepository, IndexRepository{ 31 | 32 | public Content createContent(String id, String name, String type, File contentFile) throws ContentException; 33 | 34 | public void registerMapper(String target, String modelName, BasicRowMapper mapper) throws UnknowRepositoryTargetException; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/RowAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository; 17 | 18 | import java.nio.ByteBuffer; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.UUID; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Jan 26, 2015 27 | */ 28 | public interface RowAdapter { 29 | 30 | public String getString(String name); 31 | 32 | public Integer getInt(String name); 33 | 34 | public Long getLong(String name); 35 | 36 | public Double getDouble(String name); 37 | 38 | public List getList(String name, Class type); 39 | 40 | public Map getMap(String name, Class keyType, Class valueType); 41 | 42 | public ByteBuffer getBytes(String name); 43 | 44 | public UUID getUUID(String name); 45 | } 46 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/StructuredRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository; 17 | 18 | import java.util.List; 19 | 20 | import org.cradle.repository.key.RestSearchKey; 21 | import org.cradle.repository.key.exception.InvalidCriteriaException; 22 | import org.cradle.repository.query.SimpleSelectionAdapter; 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Nov 20, 2014 27 | */ 28 | 29 | /** 30 | * @author Sherief Shawky 31 | * @email mcrakens@gmail.com 32 | * @date Nov 20, 2014 33 | */ 34 | public interface StructuredRepository { 35 | 36 | public List read(RestSearchKey key) throws InvalidCriteriaException; 37 | 38 | public void write(T model); 39 | 40 | public void write(List entities); 41 | 42 | public void update(T model); 43 | 44 | public void delete(T model); 45 | 46 | public SimpleSelectionAdapter createSimpleSelectionAdapter(String modelName); 47 | 48 | public void registerStructuredMapper(String modelName, BasicRowMapper mapper); 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/UnknowRepositoryTargetException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 28, 2015 22 | */ 23 | public class UnknowRepositoryTargetException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public UnknowRepositoryTargetException(String name) { 34 | super("Target repository: " + name + " is unknown or not supported."); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/CassandraRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra; 17 | 18 | import org.cradle.repository.BasicRowMapper; 19 | import org.springframework.cassandra.core.RowMapper; 20 | 21 | import com.datastax.driver.core.Row; 22 | import com.datastax.driver.core.exceptions.DriverException; 23 | 24 | /** 25 | * @author Sherief Shawky 26 | * @email mcrakens@gmail.com 27 | * @date Jan 26, 2015 28 | */ 29 | public class CassandraRowMapper implements RowMapper{ 30 | 31 | private BasicRowMapper rowMapper; 32 | 33 | public CassandraRowMapper(BasicRowMapper rowMapper) { 34 | this.rowMapper = rowMapper; 35 | } 36 | 37 | /* (non-Javadoc) 38 | * @see org.springframework.cassandra.core.RowMapper#mapRow(com.datastax.driver.core.Row, int) 39 | */ 40 | @Override 41 | public T mapRow(Row row, int rowNum) throws DriverException { 42 | 43 | return rowMapper.map(new CassandraRowAdapter(row)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/AndCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.criteriahandlers; 5 | 6 | import org.cradle.repository.key.RestCriteria; 7 | 8 | import com.datastax.driver.core.querybuilder.Select.Where; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Sep 8, 2014 14 | */ 15 | public class AndCriteria extends BasicCriteriaHandler { 16 | 17 | /* (non-Javadoc) 18 | * @see org.cradle.repository.cassandra.criteriahandlers.BasicCriteriaHandler#resolveCriteria(org.cradle.repository.key.RestCriteria, com.datastax.driver.core.querybuilder.Select.Where) 19 | */ 20 | @Override 21 | protected void resolveCriteria(RestCriteria criteria, Where query) 22 | throws Exception { 23 | 24 | String[] ids = criteria.readCriteriaNames(); 25 | 26 | for(int i = 0; i < ids.length; i++) 27 | query = query.and(readClause(ids[i])); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/BasicCriteriaHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.criteriahandlers; 5 | 6 | import java.util.Map; 7 | 8 | import org.cradle.repository.key.RestCriteria; 9 | import org.cradle.repository.key.exception.InvalidCriteriaException; 10 | 11 | import com.datastax.driver.core.querybuilder.Clause; 12 | import com.datastax.driver.core.querybuilder.Select.Where; 13 | 14 | /** 15 | * @author Sherief Shawky 16 | * @email mcrakens@gmail.com 17 | * @date Sep 8, 2014 18 | */ 19 | public abstract class BasicCriteriaHandler implements CriteriaHandler { 20 | 21 | private Map criterias; 22 | private String id; 23 | 24 | /* (non-Javadoc) 25 | * @see org.cradle.repository.cassandra.criteriahandlers.CriteriaHandler#handle(org.cradle.repository.key.RestCriteria, java.util.Map, com.datastax.driver.core.querybuilder.Select.Where) 26 | */ 27 | @Override 28 | public void handle(RestCriteria criteria, Map criterias, 29 | Where query) throws InvalidCriteriaException { 30 | 31 | try { 32 | 33 | this.criterias = criterias; 34 | 35 | String id = criteria.readCriteriaId(); 36 | 37 | this.id = id; 38 | 39 | resolveCriteria(criteria, query); 40 | 41 | } catch (Exception e) { 42 | 43 | throw new InvalidCriteriaException(e); 44 | } 45 | 46 | } 47 | 48 | protected void addClause(Clause clause){ 49 | criterias.put(id, clause); 50 | } 51 | 52 | protected Clause readClause(String id){ 53 | return criterias.get(id); 54 | } 55 | 56 | protected abstract void resolveCriteria( 57 | RestCriteria criteria, Where query) throws Exception; 58 | } 59 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/BetweenCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.criteriahandlers; 5 | 6 | import org.cradle.repository.key.RestCriteria; 7 | import org.cradle.repository.key.exception.InvalidCriteriaException; 8 | 9 | import com.datastax.driver.core.querybuilder.QueryBuilder; 10 | import com.datastax.driver.core.querybuilder.Select.Where; 11 | 12 | /** 13 | * @author Sherief Shawky 14 | * @email mcrakens@gmail.com 15 | * @date Sep 9, 2014 16 | */ 17 | public class BetweenCriteria extends BasicCriteriaHandler { 18 | 19 | /* (non-Javadoc) 20 | * @see org.cradle.repository.cassandra.criteriahandlers.BasicCriteriaHandler#resolveCriteria(org.cradle.repository.key.RestCriteria, com.datastax.driver.core.querybuilder.Select.Where) 21 | */ 22 | @Override 23 | protected void resolveCriteria(RestCriteria criteria, Where query) 24 | throws Exception { 25 | 26 | Object[] range = criteria.getParsedValues(); 27 | 28 | String criteriaName = criteria.readCriteriaName(); 29 | 30 | if(range.length > 2 || range.length < 2) 31 | throw new InvalidCriteriaException("between requires range of two."); 32 | 33 | query.and(QueryBuilder.lte(criteriaName, range[0])) 34 | .and(QueryBuilder.gte(criteriaName, range[1])); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/CriteriaHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.criteriahandlers; 5 | 6 | import java.util.Map; 7 | 8 | import org.cradle.repository.key.RestCriteria; 9 | import org.cradle.repository.key.exception.InvalidCriteriaException; 10 | 11 | import com.datastax.driver.core.querybuilder.Clause; 12 | import com.datastax.driver.core.querybuilder.Select.Where; 13 | 14 | /** 15 | * @author Sherief Shawky 16 | * @email mcrakens@gmail.com 17 | * @date Sep 8, 2014 18 | */ 19 | public interface CriteriaHandler { 20 | 21 | public void handle( 22 | RestCriteria criteria, 23 | Map criterias, 24 | Where query 25 | ) throws InvalidCriteriaException; 26 | } 27 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/EqualCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.criteriahandlers; 5 | 6 | import org.cradle.repository.key.RestCriteria; 7 | 8 | import com.datastax.driver.core.querybuilder.QueryBuilder; 9 | import com.datastax.driver.core.querybuilder.Select.Where; 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Sep 8, 2014 15 | */ 16 | public class EqualCriteria extends BasicCriteriaHandler { 17 | 18 | /* (non-Javadoc) 19 | * @see org.cradle.repository.cassandra.criteriahandlers.BasicCriteriaHandler#resolveCriteria(org.cradle.repository.key.RestCriteria, com.datastax.driver.core.querybuilder.Select.Where) 20 | */ 21 | @Override 22 | protected void resolveCriteria(RestCriteria criteria, Where query) 23 | throws Exception { 24 | 25 | addClause( 26 | QueryBuilder.eq( 27 | criteria.readCriteriaName(), 28 | criteria.getParsedValue() 29 | ) 30 | ); 31 | 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/InCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.criteriahandlers; 5 | 6 | import org.cradle.repository.key.RestCriteria; 7 | 8 | import com.datastax.driver.core.querybuilder.QueryBuilder; 9 | import com.datastax.driver.core.querybuilder.Select.Where; 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Sep 8, 2014 15 | */ 16 | public class InCriteria extends BasicCriteriaHandler{ 17 | 18 | /* (non-Javadoc) 19 | * @see org.cradle.repository.cassandra.criteriahandlers.BasicCriteriaHandler#resolveCriteria(org.cradle.repository.key.RestCriteria, com.datastax.driver.core.querybuilder.Select.Where) 20 | */ 21 | @Override 22 | protected void resolveCriteria(RestCriteria criteria, Where query) 23 | throws Exception { 24 | 25 | addClause( 26 | QueryBuilder.in( 27 | criteria.readCriteriaName(), 28 | criteria.getParsedValues() 29 | ) 30 | ); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/criteriahandlers/LeCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra.criteriahandlers; 17 | 18 | import org.cradle.repository.key.RestCriteria; 19 | 20 | import com.datastax.driver.core.querybuilder.QueryBuilder; 21 | import com.datastax.driver.core.querybuilder.Select.Where; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Sep 8, 2014 27 | */ 28 | public class LeCriteria extends BasicCriteriaHandler { 29 | 30 | /* (non-Javadoc) 31 | * @see org.cradle.repository.cassandra.criteriahandlers.BasicCriteriaHandler#resolveCriteria(org.cradle.repository.key.RestCriteria, com.datastax.driver.core.querybuilder.Select.Where) 32 | */ 33 | @Override 34 | protected void resolveCriteria(RestCriteria criteria, Where query) 35 | throws Exception { 36 | 37 | addClause( 38 | QueryBuilder.lte( 39 | criteria.readCriteriaName(), 40 | criteria.getParsedValue() 41 | ) 42 | ); 43 | 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/AccountRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.mappers; 5 | 6 | import org.cradle.repository.BasicRowMapper; 7 | import org.cradle.repository.RowAdapter; 8 | import org.cradle.repository.models.account.Account; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Nov 9, 2014 14 | */ 15 | public class AccountRowMapper extends BasicRowMapper { 16 | 17 | /* (non-Javadoc) 18 | * @see org.cradle.repository.BasicRowMapper#map(org.cradle.repository.RowAdapter) 19 | */ 20 | @Override 21 | public Account map(RowAdapter row) { 22 | 23 | return new Account( 24 | row.getString("email"), 25 | row.getString("password"), 26 | row.getList("roles", String.class) 27 | ); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/BasicCassandraMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra.mappers; 17 | 18 | import org.springframework.cassandra.core.RowMapper; 19 | 20 | import com.datastax.driver.core.Row; 21 | import com.datastax.driver.core.exceptions.DriverException; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Jan 26, 2015 27 | */ 28 | public class BasicCassandraMapper implements RowMapper { 29 | 30 | /* (non-Javadoc) 31 | * @see org.springframework.cassandra.core.RowMapper#mapRow(com.datastax.driver.core.Row, int) 32 | */ 33 | @Override 34 | public T mapRow(Row row, int rowNum) throws DriverException { 35 | // TODO Auto-generated method stub 36 | return null; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/ContentRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra.mappers; 17 | 18 | import org.cradle.repository.BasicRowMapper; 19 | import org.cradle.repository.RowAdapter; 20 | import org.cradle.repository.models.content.Content; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Nov 30, 2014 26 | */ 27 | public class ContentRowMapper extends BasicRowMapper{ 28 | 29 | /* (non-Javadoc) 30 | * @see org.cradle.repository.BasicRowMapper#map(org.cradle.repository.RowAdapter) 31 | */ 32 | @Override 33 | public Content map(RowAdapter row) { 34 | 35 | return new Content( 36 | row.getString("id"), 37 | row.getString("name"), 38 | row.getString("type"), 39 | row.getMap("metainfo", String.class, String.class), 40 | row.getBytes("data") 41 | ); 42 | } 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/OauthRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra.mappers; 17 | 18 | import org.cradle.repository.BasicRowMapper; 19 | import org.cradle.repository.RowAdapter; 20 | import org.cradle.repository.models.account.Oauth; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Jan 19, 2015 26 | */ 27 | public class OauthRowMapper extends BasicRowMapper { 28 | 29 | /* (non-Javadoc) 30 | * @see org.cradle.repository.BasicRowMapper#map(org.cradle.repository.RowAdapter) 31 | */ 32 | @Override 33 | public Oauth map(RowAdapter row) { 34 | 35 | return new Oauth( 36 | row.getString("email"), 37 | row.getString("oauth_provider"), 38 | row.getString("oauth_token"), 39 | row.getString("secret"), 40 | row.getString("raw_response"), 41 | row.getLong("last_access") 42 | ); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/ProfileRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra.mappers; 17 | 18 | import org.cradle.repository.BasicRowMapper; 19 | import org.cradle.repository.RowAdapter; 20 | import org.cradle.repository.models.account.Profile; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Jan 15, 2015 26 | */ 27 | public class ProfileRowMapper extends BasicRowMapper { 28 | 29 | /* (non-Javadoc) 30 | * @see org.cradle.repository.BasicRowMapper#map(org.cradle.repository.RowAdapter) 31 | */ 32 | @Override 33 | public Profile map(RowAdapter row) { 34 | 35 | return new Profile( 36 | row.getString("email"), 37 | row.getString("first_name"), 38 | row.getString("last_name") 39 | ); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/RoleRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.cassandra.mappers; 5 | 6 | import org.cradle.repository.BasicRowMapper; 7 | import org.cradle.repository.RowAdapter; 8 | import org.cradle.repository.models.account.Role; 9 | 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Nov 9, 2014 15 | */ 16 | public class RoleRowMapper extends BasicRowMapper{ 17 | 18 | /* (non-Javadoc) 19 | * @see org.cradle.repository.BasicRowMapper#map(org.cradle.repository.RowAdapter) 20 | */ 21 | @Override 22 | public Role map(RowAdapter row) { 23 | return new Role( 24 | row.getString("name"), 25 | row.getList("permissions", String.class) 26 | ); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/cassandra/mappers/TrackingLogRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.cassandra.mappers; 17 | 18 | import org.cradle.repository.BasicRowMapper; 19 | import org.cradle.repository.RowAdapter; 20 | import org.cradle.repository.models.tracking.TrackingLog; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Jan 12, 2015 26 | */ 27 | public class TrackingLogRowMapper extends BasicRowMapper { 28 | 29 | /* (non-Javadoc) 30 | * @see org.cradle.repository.BasicRowMapper#map(org.cradle.repository.RowAdapter) 31 | */ 32 | @Override 33 | public TrackingLog map(RowAdapter row) { 34 | 35 | return new TrackingLog( 36 | row.getString("method"), 37 | row.getString("resource_name"), 38 | row.getList("resource_id", String.class), 39 | row.getString("user_id"), 40 | row.getLong("timing") 41 | ); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/exception/ContentException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.exception; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Dec 1, 2014 22 | */ 23 | public class ContentException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public ContentException(Throwable e) { 34 | 35 | super("Error while processing content", e); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/exception/NoResultException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.exception; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Sep 14, 2014 22 | */ 23 | public class NoResultException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public NoResultException() { 34 | super("Query could not return any results."); 35 | } 36 | 37 | public NoResultException(Throwable e){ 38 | super("Query could not return any results." + e); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/Core.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Jan 28, 2015 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.TYPE) 30 | public @interface Core { 31 | 32 | String value(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/CoreAnnotationIsNotPresent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 28, 2015 22 | */ 23 | public class CoreAnnotationIsNotPresent extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public CoreAnnotationIsNotPresent() { 34 | 35 | super("You must add core annotation for indexable models"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/Index.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Jan 28, 2015 27 | */ 28 | 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface Index { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/IndexDocumentObjectFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.index; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Nov 19, 2014 10 | */ 11 | public interface IndexDocumentObjectFactory { 12 | public T createDocument(); 13 | } 14 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/IndexException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.index; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Nov 19, 2014 10 | */ 11 | public class IndexException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public IndexException(Throwable e) { 22 | super("Error while indexing target", e); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/IndexId.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Sherief Shawky 25 | * @email mcrakens@gmail.com 26 | * @date Jan 29, 2015 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.FIELD) 30 | public @interface IndexId { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/IndexPorter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.index; 5 | 6 | 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Nov 19, 2014 12 | */ 13 | public interface IndexPorter { 14 | 15 | public void port(T model) throws IndexException; 16 | 17 | public void delete(T model) throws IndexException; 18 | 19 | public void deleteById(String id) throws IndexException; 20 | 21 | public void commit() throws IndexException; 22 | 23 | public void shutdown(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/IndexQueryAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.index; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Nov 19, 2014 12 | */ 13 | public interface IndexQueryAdapter { 14 | 15 | public IndexQueryAdapter queryAll(); 16 | 17 | public IndexQueryAdapter query(String terms); 18 | 19 | public IndexQueryAdapter filter(String fieldName); 20 | 21 | public IndexQueryAdapter eq(String value); 22 | 23 | public IndexQueryAdapter gt(String value); 24 | 25 | public IndexQueryAdapter or(); 26 | 27 | public IndexQueryAdapter and(); 28 | 29 | public IndexQueryAdapter start(Integer start); 30 | 31 | public IndexQueryAdapter page(Integer count); 32 | 33 | public IndexQueryAdapter sort(String fieldName, boolean asc); 34 | 35 | public List result() throws QueryException; 36 | } 37 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/QueryException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.index; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Nov 19, 2014 10 | */ 11 | public class QueryException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public QueryException(Throwable e) { 22 | 23 | super("Error while querying index", e); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/TargetHasNoIndexableFileds.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 28, 2015 22 | */ 23 | public class TargetHasNoIndexableFileds extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public TargetHasNoIndexableFileds() { 34 | 35 | super("At least one filed should has Index annotation present."); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/solrj/PortingCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index.solrj; 17 | 18 | import org.cradle.repository.index.IndexException; 19 | import org.cradle.repository.index.IndexPorter; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Jan 29, 2015 25 | */ 26 | public abstract class PortingCommand { 27 | 28 | public abstract void execute(T model, IndexPorter porter) throws IndexException; 29 | } -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/index/solrj/SolrjRowMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.index.solrj; 17 | 18 | import org.apache.solr.common.SolrDocument; 19 | import org.cradle.repository.BasicRowMapper; 20 | 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Jan 28, 2015 26 | */ 27 | public class SolrjRowMapper { 28 | 29 | private BasicRowMapper rowMapper; 30 | 31 | public SolrjRowMapper(BasicRowMapper rowMapper) { 32 | this.rowMapper = rowMapper; 33 | } 34 | 35 | public T mapDocument(SolrDocument document){ 36 | 37 | return rowMapper.map(new SolrjRowAdapter(document)); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/RestProjection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key; 5 | 6 | /** 7 | * @author Raken 8 | * 9 | */ 10 | public class RestProjection { 11 | 12 | public String propertyName; 13 | 14 | public String function; 15 | 16 | public RestProjection(String projection){ 17 | readFunction(projection); 18 | readPropertyName(projection); 19 | } 20 | 21 | public String getPropertyName() { 22 | return propertyName; 23 | } 24 | public String getFunction() { 25 | return function; 26 | } 27 | 28 | private void readFunction(String projection){ 29 | 30 | int openBracketPlace = projection.indexOf('('); 31 | 32 | function = projection.substring(0, openBracketPlace).toLowerCase(); 33 | } 34 | 35 | private void readPropertyName(String projection){ 36 | 37 | int openBracketPlace = projection.indexOf('('); 38 | 39 | int closeBracketPlace = projection.indexOf(')'); 40 | 41 | propertyName = projection.substring(openBracketPlace + 1, closeBracketPlace); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/BadCriteriaValueException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author Raken 8 | * 9 | */ 10 | public class BadCriteriaValueException extends Exception { 11 | 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | 17 | public BadCriteriaValueException(String value){ 18 | super("Bad Criteria Value: " + value); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/CriteriaNotFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 4, 2014 10 | */ 11 | public class CriteriaNotFoundException extends Exception{ 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public CriteriaNotFoundException(String crt) { 22 | super("Could not find criteria: " + crt); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/InvalidCriteriaException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 4, 2014 10 | */ 11 | public class InvalidCriteriaException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public InvalidCriteriaException(Throwable e) { 22 | super("Invalid criteria", e); 23 | } 24 | 25 | public InvalidCriteriaException(String name){ 26 | super("Invalid criteria " + name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/InvalidCriteriaSyntaxException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Sherief Shawky(raken123@yahoo.com) 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author Sherief Shawky(raken123@yahoo.com) 8 | * 9 | */ 10 | public class InvalidCriteriaSyntaxException extends Exception { 11 | 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | 17 | public InvalidCriteriaSyntaxException(Throwable e){ 18 | super("Criteria Specified is Invalid, check the nested exception.", e); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/InvalidKeyException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author sherif.shawky 8 | * 9 | */ 10 | public class InvalidKeyException extends Exception { 11 | 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = 1L; 16 | 17 | public InvalidKeyException(){ 18 | super("Key is invalid"); 19 | } 20 | 21 | public InvalidKeyException(Throwable e){ 22 | super("Key is invalid", e); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/ServerFunctionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 9, 2014 10 | */ 11 | public class ServerFunctionException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public ServerFunctionException(Throwable e) { 22 | super("Function execetion failed", e); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/exception/UnknowModelException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 7, 2014 10 | */ 11 | public class UnknowModelException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public UnknowModelException(String modelName) { 22 | super("Unknow model: " + modelName); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/functions/ServerFunctionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.functions; 5 | 6 | import org.cradle.repository.StructuredRepository; 7 | import org.cradle.repository.key.RestCriteria; 8 | import org.cradle.repository.key.exception.ServerFunctionException; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Sep 9, 2014 14 | */ 15 | public interface ServerFunctionHandler { 16 | 17 | /** 18 | * @param crt 19 | * @param repository 20 | * @param resourceName 21 | * @throws ServerFunctionException 22 | */ 23 | void handle( 24 | RestCriteria crt, 25 | StructuredRepository repository, 26 | String propertyName, 27 | String resourceName 28 | ) throws ServerFunctionException; 29 | } 30 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/functions/dateback/formatter/DateBackResultFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.functions.dateback.formatter; 5 | 6 | import org.cradle.datetime.DateTimeOperation; 7 | import org.cradle.datetime.dateback.DateBackStrategy; 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Sep 17, 2014 13 | */ 14 | public interface DateBackResultFormatter { 15 | 16 | public static final String DAYS = "days"; 17 | public static final String WEEKS = "weeks"; 18 | public static final String MONTHS = "months"; 19 | public static final String YEARS = "years"; 20 | public static final String ZERO_CLOCK = "000000"; 21 | public static final String DATE_FORMAT = "yyyyMMdd"; 22 | public static final String DATE_TIME_FORMAT = "yyyyMMdd HHmmss"; 23 | 24 | public String createResult(DateBackStrategy strategy, int amount, DateTimeOperation start); 25 | } 26 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/functions/dateback/formatter/ListDateBackResultFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.key.functions.dateback.formatter; 17 | 18 | import org.cradle.datetime.DateTimeOperation; 19 | import org.cradle.datetime.dateback.DateBackStrategy; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Sep 17, 2014 25 | */ 26 | public class ListDateBackResultFormatter implements DateBackResultFormatter{ 27 | 28 | /* (non-Javadoc) 29 | * @see org.cradle.repository.key.functions.dateback.DateBackResult#createResult() 30 | */ 31 | @Override 32 | public String createResult(DateBackStrategy strategy, int amount, DateTimeOperation start) { 33 | 34 | StringBuilder result = new StringBuilder(); 35 | 36 | amount = appendElement(amount, start, result); 37 | 38 | while(amount >= 0){ 39 | 40 | result.append(","); 41 | 42 | start = strategy.back(start, 1); 43 | 44 | amount = appendElement(amount, start, result); 45 | } 46 | 47 | return result.toString(); 48 | } 49 | 50 | private int appendElement(int amount, DateTimeOperation start, StringBuilder result) { 51 | 52 | amount--; 53 | 54 | result.append(start.getMilliseconds()); 55 | 56 | return amount; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/functions/dateback/formatter/OneItemDateBackResultFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.key.functions.dateback.formatter; 17 | 18 | import org.cradle.datetime.DateTimeOperation; 19 | import org.cradle.datetime.dateback.DateBackStrategy; 20 | 21 | /** 22 | * @author Sherief Shawky 23 | * @email mcrakens@gmail.com 24 | * @date Sep 17, 2014 25 | */ 26 | public class OneItemDateBackResultFormatter implements DateBackResultFormatter { 27 | 28 | /* (non-Javadoc) 29 | * @see org.cradle.repository.key.functions.dateback.DateBackResult#createResult() 30 | */ 31 | @Override 32 | public String createResult(DateBackStrategy strategy, int amount, DateTimeOperation start) { 33 | 34 | StringBuilder result = new StringBuilder(); 35 | 36 | result.append(strategy.back(start, amount).getMilliseconds()); 37 | 38 | return result.toString(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/generator/KeyGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.generator; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import org.cradle.repository.key.RestSearchKey; 10 | import org.cradle.repository.key.exception.InvalidKeyException; 11 | 12 | /** 13 | * @author Sherief Shawky 14 | * @email mcrakens@gmail.com 15 | * @date Sep 23, 2014 16 | */ 17 | public interface KeyGenerator { 18 | 19 | public List generateKeys(Map params) throws InvalidKeyException; 20 | } 21 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/parsers/GsonKeyParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.key.parsers; 5 | 6 | import java.lang.reflect.Type; 7 | import java.util.List; 8 | 9 | import org.cradle.repository.key.RestSearchKey; 10 | import org.cradle.repository.key.exception.InvalidKeyException; 11 | 12 | import com.google.gson.Gson; 13 | import com.google.gson.GsonBuilder; 14 | import com.google.gson.reflect.TypeToken; 15 | 16 | /** 17 | * @author Raken 18 | * 19 | */ 20 | public class GsonKeyParser implements KeyParser{ 21 | 22 | private Gson gson; 23 | 24 | 25 | public GsonKeyParser(){ 26 | gson = new GsonBuilder().create(); 27 | } 28 | 29 | @Override 30 | public List parseKey(String key) throws InvalidKeyException { 31 | 32 | Type listType = new TypeToken>() {}.getType(); 33 | 34 | try{ 35 | List keys = gson.fromJson(key, listType); 36 | 37 | for(RestSearchKey rKey:keys) 38 | rKey.parseAllCriterias(); 39 | 40 | return keys; 41 | 42 | }catch(Exception e){ 43 | throw new InvalidKeyException(e); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/key/parsers/KeyParser.java: -------------------------------------------------------------------------------- 1 | package org.cradle.repository.key.parsers; 2 | 3 | import java.util.List; 4 | 5 | import org.cradle.repository.key.RestSearchKey; 6 | import org.cradle.repository.key.exception.InvalidKeyException; 7 | 8 | public interface KeyParser { 9 | public List parseKey(String key) throws InvalidKeyException; 10 | } 11 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/models/RestModel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.models; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 3, 2014 10 | */ 11 | public interface RestModel { 12 | public Object getUniqueId(); 13 | } 14 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/models/account/Role.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.models.account; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | import org.cradle.repository.models.RestModel; 10 | import org.springframework.data.cassandra.mapping.PrimaryKey; 11 | import org.springframework.data.cassandra.mapping.Table; 12 | 13 | /** 14 | * @author Sherief Shawky 15 | * @email mcrakens@gmail.com 16 | * @date Nov 9, 2014 17 | */ 18 | @Table("role") 19 | public class Role implements RestModel, Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = -1159549367935523615L; 25 | 26 | @PrimaryKey 27 | private String name; 28 | 29 | private List permissions; 30 | 31 | 32 | public Role(String name, List permissions) { 33 | this.name = name; 34 | this.permissions = permissions; 35 | 36 | } 37 | 38 | public boolean equals(Role role){ 39 | 40 | if(name.equals(role.name)) 41 | return true; 42 | 43 | return false; 44 | } 45 | 46 | /** 47 | * @return the permissions 48 | */ 49 | public List getPermissions() { 50 | 51 | return permissions; 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see org.cradle.repository.models.RestModel#getUniqueId() 56 | */ 57 | @Override 58 | public Object getUniqueId() { 59 | return name; 60 | } 61 | 62 | public boolean nameEquals(String targetName){ 63 | 64 | return name.equalsIgnoreCase(targetName); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/query/SimpleSelectionAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.repository.query; 17 | 18 | import java.util.List; 19 | 20 | import org.cradle.repository.exception.NoResultException; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Aug 31, 2014 26 | */ 27 | public interface SimpleSelectionAdapter { 28 | 29 | public SimpleSelectionAdapter eq(String name, Object value); 30 | 31 | public SimpleSelectionAdapter gt(String name, Object value); 32 | 33 | public SimpleSelectionAdapter gte(String name, Object value); 34 | 35 | public SimpleSelectionAdapter and(); 36 | 37 | public SimpleSelectionAdapter or(); 38 | 39 | public SimpleSelectionAdapter orderBy(boolean asc, String... columns); 40 | 41 | public SimpleSelectionAdapter page(int size); 42 | 43 | public SimpleSelectionAdapter lt(String name, Object value); 44 | 45 | public List result() throws NoResultException; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /repository/src/main/java/org/cradle/repository/query/formatter/QueryResultFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.repository.query.formatter; 5 | 6 | import java.util.Map; 7 | 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Sep 23, 2014 13 | */ 14 | public interface QueryResultFormatter { 15 | 16 | public Map format(Map result); 17 | } 18 | -------------------------------------------------------------------------------- /repository/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: repository 4 | Bundle-SymbolicName: repository 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /repository/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /schedule/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/JobBuildResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 21, 2014 10 | */ 11 | public class JobBuildResult { 12 | public boolean scheduled; 13 | public JobBuilder builder; 14 | } 15 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/JobBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule; 5 | 6 | import org.cradle.schedule.exception.ScheduleException; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 11, 2014 12 | */ 13 | public interface JobBuilder { 14 | 15 | public void scheulde() throws ScheduleException; 16 | 17 | public void scheulde(String calendarName) throws ScheduleException; 18 | 19 | public JobBuilder secondly(int interval); 20 | 21 | public JobBuilder secondly(int count, int interval); 22 | 23 | public JobBuilder daily(int hour, int minute); 24 | 25 | public JobBuilder weekly(int day, int hour, int minute); 26 | 27 | public JobBuilder ignoreMisfires(); 28 | 29 | public JobBuilder runOnceOnMisfire(); 30 | 31 | public JobBuilder inTimeZone(String timeZone); 32 | } 33 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/ScheduleContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * @author Sherief Shawky 10 | * @email mcrakens@gmail.com 11 | * @date Sep 11, 2014 12 | */ 13 | public interface ScheduleContext { 14 | 15 | public Date getScheduledTime(); 16 | 17 | public Date getNextFireTime(); 18 | } 19 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/ScheduleService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule; 5 | 6 | import java.util.Date; 7 | 8 | import org.cradle.schedule.exception.ScheduleException; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Sep 11, 2014 14 | */ 15 | public interface ScheduleService { 16 | 17 | public JobBuildResult buildJob(String jobName, String scheduleName, ScheduledJob job, boolean replace) throws ScheduleException; 18 | 19 | public void removeJob(String jobName, String scheduleName) throws ScheduleException; 20 | 21 | public boolean taskExists(String jobName, String scheduleName) throws ScheduleException; 22 | 23 | public Date getFireTime(String jobName, String scheduleName) throws ScheduleException; 24 | } -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/ScheduledJob.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule; 5 | 6 | import java.io.Serializable; 7 | 8 | import org.cradle.schedule.exception.ScheduleException; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Sep 10, 2014 14 | */ 15 | public interface ScheduledJob extends Serializable{ 16 | 17 | public void execute(ScheduleContext context) throws ScheduleException; 18 | } 19 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/ScheduledJobListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 9, 2014 10 | */ 11 | public interface ScheduledJobListener { 12 | 13 | public void onExceute(); 14 | } 15 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/exception/ScheduleException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.exception; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 11, 2014 10 | */ 11 | public class ScheduleException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public ScheduleException(Throwable e) { 22 | super("Error occured while executing job", e); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/QuartzJob.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz; 5 | 6 | import org.cradle.schedule.ScheduledJob; 7 | import org.quartz.Job; 8 | import org.quartz.JobExecutionContext; 9 | import org.quartz.JobExecutionException; 10 | import org.quartz.JobKey; 11 | import org.quartz.SchedulerContext; 12 | import org.quartz.SchedulerException; 13 | 14 | 15 | /** 16 | * @author Sherief Shawky 17 | * @email mcrakens@gmail.com 18 | * @date Sep 11, 2014 19 | */ 20 | public class QuartzJob implements Job{ 21 | 22 | /* (non-Javadoc) 23 | * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) 24 | */ 25 | @Override 26 | public void execute(JobExecutionContext context) 27 | throws JobExecutionException { 28 | 29 | try { 30 | 31 | ScheduledJob scheduledJob = getScheduledJob(context); 32 | 33 | if(scheduledJob != null) { 34 | 35 | QuartzScheduleContext scheduleContext = new QuartzScheduleContext(context); 36 | 37 | scheduledJob.execute(scheduleContext); 38 | } 39 | 40 | } catch (Exception e) { 41 | 42 | throw new JobExecutionException(e); 43 | } 44 | } 45 | 46 | private ScheduledJob getScheduledJob(JobExecutionContext context) 47 | throws SchedulerException { 48 | 49 | SchedulerContext schedulerContext = context.getScheduler().getContext(); 50 | 51 | String registeredJobName = getRegisteredName(context); 52 | 53 | ScheduledJob scheduledJob = (ScheduledJob) schedulerContext.get(registeredJobName); 54 | 55 | return scheduledJob; 56 | } 57 | 58 | private String getRegisteredName(JobExecutionContext context) { 59 | 60 | JobKey jobKey = context.getJobDetail().getKey(); 61 | 62 | String registeredJobName = jobKey.getName() + "." + jobKey.getGroup(); 63 | 64 | return registeredJobName; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/QuartzScheduleContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz; 5 | 6 | import java.util.Date; 7 | 8 | import org.cradle.schedule.ScheduleContext; 9 | import org.quartz.JobExecutionContext; 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Sep 11, 2014 15 | */ 16 | public class QuartzScheduleContext implements ScheduleContext{ 17 | 18 | private JobExecutionContext context; 19 | 20 | public QuartzScheduleContext(JobExecutionContext context) { 21 | 22 | this.context = context; 23 | } 24 | 25 | /* (non-Javadoc) 26 | * @see org.cradle.schedule.ScheduleContext#getScheduledTime() 27 | */ 28 | @Override 29 | public Date getScheduledTime() { 30 | 31 | return context.getScheduledFireTime(); 32 | } 33 | 34 | /* (non-Javadoc) 35 | * @see org.cradle.schedule.ScheduleContext#getNextFireTime() 36 | */ 37 | @Override 38 | public Date getNextFireTime() { 39 | 40 | return context.getNextFireTime(); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/builder/calendar/BasicCalendarBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz.builder.calendar; 5 | 6 | import java.util.TimeZone; 7 | 8 | import org.quartz.Scheduler; 9 | import org.quartz.SchedulerException; 10 | import org.quartz.impl.calendar.BaseCalendar; 11 | 12 | /** 13 | * @author Sherief Shawky 14 | * @email mcrakens@gmail.com 15 | * @date Oct 8, 2014 16 | */ 17 | public abstract class BasicCalendarBuilder implements CalendarBuilder{ 18 | 19 | private String name; 20 | 21 | private String timeZone; 22 | 23 | /** 24 | * @param timeZone the timeZone to set 25 | */ 26 | public void setTimeZone(String timeZone) { 27 | this.timeZone = timeZone; 28 | } 29 | 30 | /** 31 | * @param name the name to set 32 | */ 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | /* (non-Javadoc) 38 | * @see org.cradle.schedule.quartz.builder.calendar.CalendarBuilder#build(org.quartz.Scheduler) 39 | */ 40 | @Override 41 | public void build(Scheduler scheduler) throws SchedulerException { 42 | 43 | BaseCalendar cal = buildCalendar(); 44 | 45 | cal.setTimeZone(TimeZone.getTimeZone(timeZone)); 46 | 47 | scheduler.addCalendar(name, cal, true, true); 48 | } 49 | 50 | /** 51 | * @return 52 | */ 53 | protected abstract BaseCalendar buildCalendar(); 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/builder/calendar/CalendarBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz.builder.calendar; 5 | 6 | import org.quartz.Scheduler; 7 | import org.quartz.SchedulerException; 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Oct 8, 2014 13 | */ 14 | public interface CalendarBuilder { 15 | 16 | public void build(Scheduler scheduler) throws SchedulerException; 17 | } 18 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/builder/calendar/WeekCalendarBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz.builder.calendar; 5 | 6 | 7 | import org.quartz.impl.calendar.BaseCalendar; 8 | import org.quartz.impl.calendar.WeeklyCalendar; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Oct 8, 2014 14 | */ 15 | public class WeekCalendarBuilder extends BasicCalendarBuilder { 16 | 17 | private boolean exclude; 18 | 19 | private int[] days; 20 | 21 | 22 | /** 23 | * @param exclude the exclude to set 24 | */ 25 | public void setExclude(boolean exclude) { 26 | this.exclude = exclude; 27 | } 28 | 29 | /** 30 | * @param days the days to set 31 | */ 32 | public void setDays(int[] days) { 33 | this.days = days; 34 | } 35 | 36 | /* (non-Javadoc) 37 | * @see org.cradle.schedule.quartz.builder.calendar.BasicCalendarBuilder#buildCalendar() 38 | */ 39 | @Override 40 | protected BaseCalendar buildCalendar() { 41 | 42 | WeeklyCalendar cal = new WeeklyCalendar(); 43 | 44 | for(int day = java.util.Calendar.SUNDAY; day <= java.util.Calendar.SATURDAY; day++){ 45 | 46 | cal.setDayExcluded(day, !exclude); 47 | } 48 | 49 | for(int day : days){ 50 | 51 | cal.setDayExcluded(day, exclude); 52 | } 53 | 54 | return cal; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/builder/schedule/BasicScheduleBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz.builder.schedule; 5 | 6 | import org.quartz.ScheduleBuilder; 7 | import org.quartz.Trigger; 8 | import org.quartz.TriggerBuilder; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Sep 29, 2014 14 | */ 15 | public abstract class BasicScheduleBuilder implements QuartzScheduleBuilder { 16 | 17 | /* (non-Javadoc) 18 | * @see org.cradle.schedule.quartz.builder.QuartzScheduleBuilder#schedule(org.quartz.TriggerBuilder) 19 | */ 20 | @Override 21 | public void schedule(TriggerBuilder jobTriggerBuilder) { 22 | 23 | jobTriggerBuilder.withSchedule(getScheduleBuilder()); 24 | } 25 | 26 | 27 | protected abstract ScheduleBuilder getScheduleBuilder(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/builder/schedule/DailyScheduleBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz.builder.schedule; 5 | 6 | import static org.quartz.CronScheduleBuilder.dailyAtHourAndMinute; 7 | 8 | import java.util.TimeZone; 9 | 10 | import org.quartz.CronScheduleBuilder; 11 | import org.quartz.ScheduleBuilder; 12 | 13 | /** 14 | * @author Sherief Shawky 15 | * @email mcrakens@gmail.com 16 | * @date Sep 29, 2014 17 | */ 18 | public class DailyScheduleBuilder extends BasicScheduleBuilder { 19 | 20 | private CronScheduleBuilder scheduleBuilder; 21 | 22 | /** 23 | * 24 | */ 25 | public DailyScheduleBuilder(int hour, int minute) { 26 | 27 | scheduleBuilder = dailyAtHourAndMinute(hour, minute); 28 | 29 | } 30 | 31 | /* (non-Javadoc) 32 | * @see org.cradle.schedule.quartz.builder.QuartzScheduleBuilder#ignoreMisfies() 33 | */ 34 | @Override 35 | public void ignoreMisfires() { 36 | 37 | scheduleBuilder.withMisfireHandlingInstructionDoNothing(); 38 | } 39 | 40 | 41 | /* (non-Javadoc) 42 | * @see org.cradle.schedule.quartz.builder.BasicScheduleBuilder#getScheduleBuilder() 43 | */ 44 | @Override 45 | protected ScheduleBuilder getScheduleBuilder() { 46 | 47 | return scheduleBuilder; 48 | } 49 | 50 | /* (non-Javadoc) 51 | * @see org.cradle.schedule.quartz.builder.schedule.QuartzScheduleBuilder#runOnceOnMisfire() 52 | */ 53 | @Override 54 | public void runOnceOnMisfire() { 55 | 56 | scheduleBuilder.withMisfireHandlingInstructionFireAndProceed(); 57 | } 58 | 59 | /* (non-Javadoc) 60 | * @see org.cradle.schedule.quartz.builder.schedule.QuartzScheduleBuilder#inTimeZone(java.lang.String) 61 | */ 62 | @Override 63 | public void inTimeZone(String timeZone) { 64 | 65 | scheduleBuilder.inTimeZone(TimeZone.getTimeZone(timeZone)); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/quartz/builder/schedule/QuartzScheduleBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.quartz.builder.schedule; 5 | 6 | import org.quartz.Trigger; 7 | import org.quartz.TriggerBuilder; 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Sep 29, 2014 13 | */ 14 | public interface QuartzScheduleBuilder { 15 | 16 | public void ignoreMisfires(); 17 | 18 | public void runOnceOnMisfire(); 19 | 20 | public void schedule(TriggerBuilder jobTriggerBuilder); 21 | 22 | public void inTimeZone(String timeZone); 23 | } 24 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/session/SessionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.session; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 9, 2014 10 | */ 11 | public class SessionException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public SessionException(Throwable e) { 22 | super("Session error", e); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/session/SessionObserver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.session; 5 | 6 | import org.cradle.disruptor.DisruptorEventHandler; 7 | import org.cradle.reporting.SystemReportingService; 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Oct 12, 2014 13 | */ 14 | public abstract class SessionObserver extends DisruptorEventHandler implements SessionStatusCallback{ 15 | 16 | protected SystemReportingService reportingService; 17 | 18 | /** 19 | * @param reportingService the reportingService to set 20 | */ 21 | public void setReportingService(SystemReportingService reportingService) { 22 | 23 | this.reportingService = reportingService; 24 | } 25 | 26 | /* (non-Javadoc) 27 | * @see org.cradle.disruptor.DisruptorEventHandler#consume(java.lang.Object) 28 | */ 29 | @Override 30 | protected void consume(SessionStatus status) { 31 | 32 | status.apply(this); 33 | } 34 | 35 | protected abstract void init(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/session/SessionStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.session; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 12, 2014 10 | */ 11 | public class SessionStatus { 12 | 13 | public static final String IN_SESSION = "insession"; 14 | public static final String OUT_SESSION = "outsession"; 15 | public static final String START_SESSION = "startsession"; 16 | public static final String END_SESSION = "endsession"; 17 | 18 | private String type; 19 | 20 | public SessionStatus(String type) { 21 | this.type = type; 22 | } 23 | 24 | /** 25 | * @return the type 26 | */ 27 | public String getType() { 28 | return type; 29 | } 30 | 31 | public void apply(SessionStatusCallback sessionCallback){ 32 | 33 | switch (type){ 34 | 35 | case IN_SESSION: 36 | sessionCallback.inSession(); 37 | break; 38 | 39 | case OUT_SESSION: 40 | sessionCallback.outSession(); 41 | break; 42 | 43 | case START_SESSION: 44 | sessionCallback.startSession(); 45 | break; 46 | 47 | case END_SESSION: 48 | sessionCallback.endSession(); 49 | break; 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/session/SessionStatusCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.session; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Oct 12, 2014 10 | */ 11 | public interface SessionStatusCallback { 12 | 13 | public void inSession(); 14 | 15 | public void outSession(); 16 | 17 | public void startSession(); 18 | 19 | public void endSession(); 20 | } 21 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/tracks/MinuteTrack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.schedule.tracks; 17 | 18 | import org.cradle.schedule.JobBuilder; 19 | import org.cradle.schedule.exception.ScheduleException; 20 | 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Sep 22, 2014 26 | */ 27 | public abstract class MinuteTrack extends Track { 28 | 29 | /** 30 | * 31 | */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | 35 | protected int minutes; 36 | 37 | 38 | /** 39 | * @param minutes the minutes to set 40 | */ 41 | public void setMinutes(int minutes) { 42 | this.minutes = minutes; 43 | } 44 | 45 | /* (non-Javadoc) 46 | * @see org.cradle.schedule.tracks.Track#scheduleTrack(org.cradle.schedule.JobBuilder) 47 | */ 48 | @Override 49 | protected void scheduleTrack(JobBuilder jobBuilder) throws ScheduleException { 50 | 51 | jobBuilder.secondly(minutes * 60) 52 | .ignoreMisfires() 53 | .scheulde(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/tracks/TrackException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.tracks; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Sep 23, 2014 10 | */ 11 | public class TrackException extends Exception { 12 | 13 | /** 14 | * 15 | */ 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 20 | */ 21 | public TrackException(Throwable e) { 22 | super("Error while executing track", e); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /schedule/src/main/java/org/cradle/schedule/tracks/WeeklyTrack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.schedule.tracks; 5 | 6 | import org.cradle.reporting.SystemReportingService; 7 | import org.cradle.schedule.JobBuilder; 8 | import org.cradle.schedule.ScheduleService; 9 | import org.cradle.schedule.exception.ScheduleException; 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Sep 29, 2014 15 | */ 16 | public abstract class WeeklyTrack extends Track { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | private int minute; 21 | 22 | private int hour; 23 | 24 | private int day; 25 | 26 | public void setMinute(int minute) { 27 | this.minute = minute; 28 | } 29 | 30 | public void setHour(int hour) { 31 | this.hour = hour; 32 | } 33 | 34 | public void setDay(int day) { 35 | this.day = day; 36 | } 37 | 38 | /** 39 | * 40 | */ 41 | public WeeklyTrack() { 42 | } 43 | 44 | 45 | public WeeklyTrack(ScheduleService scheduleService, String trackName, 46 | SystemReportingService reportingService, int minute, int hour, 47 | int day) { 48 | 49 | super(scheduleService, trackName, reportingService); 50 | 51 | this.minute = minute; 52 | this.hour = hour; 53 | this.day = day; 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see org.cradle.schedule.tracks.Track#scheduleTrack(org.cradle.schedule.JobBuilder) 58 | */ 59 | @Override 60 | protected void scheduleTrack(JobBuilder jobBuilder) throws ScheduleException { 61 | 62 | jobBuilder 63 | .weekly(day, hour, minute) 64 | .ignoreMisfires() 65 | .scheulde(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /schedule/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: schedule 4 | Bundle-SymbolicName: schedule 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /schedule/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /schedule/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /security/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /security/src/main/java/org/cradle/security/AuthenticationFailureException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.security; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Jan 18, 2015 22 | */ 23 | public class AuthenticationFailureException extends Exception { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 32 | */ 33 | public AuthenticationFailureException(Throwable e) { 34 | super("Authentication failed", e); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /security/src/main/java/org/cradle/security/SecurityService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.security; 5 | 6 | import org.cradle.repository.models.account.Account; 7 | 8 | 9 | /** 10 | * @author Sherief Shawky 11 | * @email mcrakens@gmail.com 12 | * @date Nov 9, 2014 13 | */ 14 | public interface SecurityService { 15 | 16 | public User identify(String sessionId); 17 | 18 | public void register(Account account); 19 | } 20 | -------------------------------------------------------------------------------- /security/src/main/java/org/cradle/security/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.security; 5 | 6 | /** 7 | * @author Sherief Shawky 8 | * @email mcrakens@gmail.com 9 | * @date Nov 9, 2014 10 | */ 11 | public interface User { 12 | 13 | public final String STATUS = "status"; 14 | public final String ANONYMOUS = "anonymous"; 15 | public final String HANDSHAKING = "handshaking"; 16 | public final String AUTHENTICATED = "authenticated"; 17 | 18 | public String userId(); 19 | 20 | public String sessionId(); 21 | 22 | public boolean hasSession(); 23 | 24 | public boolean isAccessible(String method, String path); 25 | 26 | public void login(String email, String password, boolean rememberMe) throws AuthenticationFailureException; 27 | 28 | public void addSessionParameter(String name, Object value); 29 | 30 | public Object readSessionParameter(String name); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /security/src/main/java/org/cradle/security/shiro/AccountAuthenticationInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.security.shiro; 5 | 6 | import org.apache.shiro.authc.AuthenticationInfo; 7 | import org.apache.shiro.subject.PrincipalCollection; 8 | import org.apache.shiro.subject.SimplePrincipalCollection; 9 | import org.cradle.repository.models.account.Account; 10 | 11 | /** 12 | * @author Sherief Shawky 13 | * @email mcrakens@gmail.com 14 | * @date Nov 9, 2014 15 | */ 16 | public class AccountAuthenticationInfo implements AuthenticationInfo{ 17 | 18 | /** 19 | * 20 | */ 21 | private static final long serialVersionUID = 1L; 22 | 23 | private Account userAccount; 24 | private PrincipalCollection principalCollection; 25 | 26 | 27 | /* (non-Javadoc) 28 | * @see org.apache.shiro.authc.AuthenticationInfo#getPrincipals() 29 | */ 30 | public AccountAuthenticationInfo(Account userAccount, String realmName) { 31 | 32 | this.userAccount = userAccount; 33 | 34 | this.principalCollection = new SimplePrincipalCollection(userAccount, realmName); 35 | } 36 | 37 | @Override 38 | public PrincipalCollection getPrincipals() { 39 | 40 | return principalCollection; 41 | } 42 | 43 | /* (non-Javadoc) 44 | * @see org.apache.shiro.authc.AuthenticationInfo#getCredentials() 45 | */ 46 | @Override 47 | public Object getCredentials() { 48 | return userAccount.getPassword(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /security/src/main/java/org/cradle/security/shiro/SimpleSessionKey.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.security.shiro; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.apache.shiro.session.mgt.SessionKey; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Dec 24, 2014 26 | */ 27 | public class SimpleSessionKey implements SessionKey { 28 | 29 | private String sessionId; 30 | 31 | public SimpleSessionKey(String sessionId) { 32 | this.sessionId = sessionId; 33 | } 34 | 35 | /* (non-Javadoc) 36 | * @see org.apache.shiro.session.mgt.SessionKey#getSessionId() 37 | */ 38 | @Override 39 | public Serializable getSessionId() { 40 | return sessionId; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /security/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: security 4 | Bundle-SymbolicName: security 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /security/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /security/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /vertx/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /vertx/src/main/java/org/cradle/platform/vertx/DeploymentReporter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.vertx; 17 | 18 | import org.cradle.reporting.SystemReportingService; 19 | import org.vertx.java.core.AsyncResult; 20 | import org.vertx.java.core.Handler; 21 | 22 | /** 23 | * @author Sherief Shawky 24 | * @email mcrakens@gmail.com 25 | * @date Aug 25, 2014 26 | */ 27 | public class DeploymentReporter implements Handler>{ 28 | 29 | private String moduleName; 30 | private SystemReportingService reportingService; 31 | 32 | public DeploymentReporter(String moduleName, SystemReportingService reportingService) { 33 | 34 | this.moduleName = moduleName; 35 | 36 | this.reportingService = reportingService; 37 | } 38 | 39 | /* (non-Javadoc) 40 | * @see org.vertx.java.core.Handler#handle(java.lang.Object) 41 | */ 42 | @Override 43 | public void handle(AsyncResult event) { 44 | 45 | reportingService.info(this.getClass().getSimpleName(), SystemReportingService.FILE, "Deployed "+ moduleName +"? " + event.succeeded()); 46 | 47 | if(event.failed()){ 48 | 49 | reportingService.exception(this.getClass().getSimpleName(), SystemReportingService.FILE, event.cause()); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /vertx/src/main/java/org/cradle/platform/vertx/HttpFilterAgent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.platform.vertx; 17 | 18 | import org.cradle.platform.httpgateway.HttpFilter; 19 | import org.cradle.platform.httpgateway.filter.PrecedenceFilter; 20 | import org.cradle.platform.spi.RegistrationAgent; 21 | 22 | import com.google.common.collect.Multimap; 23 | 24 | /** 25 | * @author Sherief Shawky 26 | * @email mcrakens@gmail.com 27 | * @date Apr 27, 2015 28 | */ 29 | public class HttpFilterAgent implements 30 | RegistrationAgent { 31 | 32 | private Multimap filters; 33 | 34 | /** 35 | * @param filters 36 | */ 37 | public HttpFilterAgent(Multimap filters) { 38 | this.filters = filters; 39 | } 40 | 41 | /* (non-Javadoc) 42 | * @see org.cradle.platform.spi.RegistrationAgent#register(java.lang.annotation.Annotation, java.lang.Object) 43 | */ 44 | @Override 45 | public void register(HttpFilter annotation, PrecedenceFilter handler) { 46 | 47 | filters.put(annotation.pattern(), handler); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /vertx/src/main/java/org/cradle/platform/vertx/eventbus/VertxTextEventbusHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.cradle.platform.vertx.eventbus; 5 | 6 | import org.cradle.platform.eventbus.spi.EventbusHandler; 7 | import org.vertx.java.core.Handler; 8 | import org.vertx.java.core.eventbus.Message; 9 | 10 | /** 11 | * @author Sherief Shawky 12 | * @email mcrakens@gmail.com 13 | * @date Aug 14, 2014 14 | */ 15 | public class VertxTextEventbusHandler implements Handler>{ 16 | 17 | private EventbusHandler textEventbusHandler; 18 | 19 | /** 20 | * @param textEventbusHandler 21 | */ 22 | public VertxTextEventbusHandler(EventbusHandler textEventbusHandler) { 23 | this.textEventbusHandler = textEventbusHandler; 24 | } 25 | 26 | /* (non-Javadoc) 27 | * @see org.vertx.java.core.Handler#handle(java.lang.Object) 28 | */ 29 | @Override 30 | public void handle(Message event) { 31 | 32 | String message = event.body(); 33 | 34 | textEventbusHandler.recieve(message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /vertx/src/main/java/org/cradle/platform/vertx/handlers/FileRequestHandler.java: -------------------------------------------------------------------------------- 1 | package org.cradle.platform.vertx.handlers; 2 | 3 | import org.vertx.java.core.Handler; 4 | import org.vertx.java.core.http.HttpServerRequest; 5 | 6 | public final class FileRequestHandler implements Handler { 7 | 8 | private String fileRoot; 9 | private String webRoot; 10 | 11 | public FileRequestHandler(String fileRoot, String webRoot) { 12 | this.fileRoot = fileRoot; 13 | this.webRoot = webRoot; 14 | } 15 | 16 | public void handle(HttpServerRequest req) { 17 | 18 | String path = req.path(); 19 | 20 | String file = getTargetFile(path); 21 | 22 | String targetPath = fileRoot + "/" + file; 23 | 24 | req.response().sendFile(targetPath); 25 | } 26 | 27 | private String getTargetFile(String path){ 28 | 29 | return path.substring(webRoot.length(), path.length()); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /vertx/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: vertx 4 | Bundle-SymbolicName: vertx 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 7 | -------------------------------------------------------------------------------- /vertx/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /vertx/src/main/resources/build.properties: -------------------------------------------------------------------------------- 1 | custom=true 2 | -------------------------------------------------------------------------------- /vertx/src/main/resources/html/webSocketMessage_Broadcast.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Send to calculate 6 | 7 | 8 | 21 | 22 | 23 |

24 | 25 | -------------------------------------------------------------------------------- /vertx/src/main/resources/html/webSocketMessage_Synchronous.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Send to calculate 6 | 7 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /vertx/src/main/resources/html/websocketMessage_Reciever.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Send Message Test 6 | 7 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /vertx/src/test/java/org/cradle/gateway/vertx/test/Calculation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.gateway.vertx.test; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Apr 16, 2015 22 | */ 23 | public class Calculation { 24 | 25 | private int num1; 26 | 27 | private int num2; 28 | 29 | private int result; 30 | 31 | /** 32 | * @return the num1 33 | */ 34 | public int getNum1() { 35 | return num1; 36 | } 37 | /** 38 | * @return the num2 39 | */ 40 | public int getNum2() { 41 | return num2; 42 | } 43 | 44 | /** 45 | * @param num1 the num1 to set 46 | */ 47 | public void setNum1(int num1) { 48 | this.num1 = num1; 49 | } 50 | /** 51 | * @param num2 the num2 to set 52 | */ 53 | public void setNum2(int num2) { 54 | this.num2 = num2; 55 | } 56 | /** 57 | * @return the result 58 | */ 59 | public int getResult() { 60 | return result; 61 | } 62 | 63 | public void calcResult() { 64 | this.result = num1 * num2; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /vertx/src/test/java/org/cradle/gateway/vertx/test/Message.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright mcplissken. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.cradle.gateway.vertx.test; 17 | 18 | /** 19 | * @author Sherief Shawky 20 | * @email mcrakens@gmail.com 21 | * @date Apr 21, 2015 22 | */ 23 | public class Message { 24 | 25 | private String sender; 26 | private String text; 27 | 28 | /** 29 | * @param sender 30 | * @param text 31 | */ 32 | public Message(String sender, String text) { 33 | this.sender = sender; 34 | this.text = text; 35 | } 36 | 37 | /** 38 | * @return the sender 39 | */ 40 | public String getSender() { 41 | return sender; 42 | } 43 | /** 44 | * @param sender the sender to set 45 | */ 46 | public void setSender(String sender) { 47 | this.sender = sender; 48 | } 49 | /** 50 | * @return the text 51 | */ 52 | public String getText() { 53 | return text; 54 | } 55 | /** 56 | * @param text the text to set 57 | */ 58 | public void setText(String text) { 59 | this.text = text; 60 | } 61 | 62 | 63 | } 64 | --------------------------------------------------------------------------------