001/**
002 * Copyright 2014 The Sculptor Project Team, including the original
003 * author or authors.
004 * 
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 * 
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.sculptor.generator.cartridge.mongodb;
018
019import javax.inject.Inject;
020import org.eclipse.xtend2.lib.StringConcatenation;
021import org.eclipse.xtext.xbase.lib.Extension;
022import org.sculptor.generator.cartridge.mongodb.MongoDbHelper;
023import org.sculptor.generator.cartridge.mongodb.MongoDbProperties;
024import org.sculptor.generator.chain.ChainOverride;
025import org.sculptor.generator.template.repository.AccessObjectFactoryTmpl;
026import sculptormetamodel.DomainObject;
027import sculptormetamodel.Module;
028import sculptormetamodel.Repository;
029import sculptormetamodel.RepositoryOperation;
030
031@ChainOverride
032@SuppressWarnings("all")
033public class AccessObjectFactoryTmplExtension extends AccessObjectFactoryTmpl {
034  @Inject
035  @Extension
036  private MongoDbHelper mongoDbHelper;
037  
038  @Inject
039  @Extension
040  private MongoDbProperties mongoDbProperties;
041  
042  @Override
043  public String factoryMethodInit(final RepositoryOperation it) {
044    AccessObjectFactoryTmpl headObj = getMethodsDispatchHead()[org.sculptor.generator.template.repository.AccessObjectFactoryTmplMethodIndexes.FACTORYMETHODINIT_REPOSITORYOPERATION];
045    return headObj._chained_factoryMethodInit(it);
046  }
047  
048  public AccessObjectFactoryTmplExtension(final AccessObjectFactoryTmpl next, final AccessObjectFactoryTmpl[] methodsDispatchNext) {
049    super(next);
050  }
051  
052  public String _chained_factoryMethodInit(final RepositoryOperation it) {
053    StringConcatenation _builder = new StringConcatenation();
054    AccessObjectFactoryTmpl _next = this.getNext();
055    String _factoryMethodInit = _next.factoryMethodInit(it);
056    _builder.append(_factoryMethodInit, "");
057    _builder.newLineIfNotEmpty();
058    {
059      boolean _mongoDb = this.mongoDbProperties.mongoDb();
060      if (_mongoDb) {
061        _builder.append("ao.setDbManager(dbManager);");
062        _builder.newLine();
063        _builder.append("ao.setDataMapper(");
064        Repository _repository = it.getRepository();
065        DomainObject _aggregateRoot = _repository.getAggregateRoot();
066        Module _module = _aggregateRoot.getModule();
067        String _mapperPackage = this.mongoDbHelper.getMapperPackage(_module);
068        _builder.append(_mapperPackage, "");
069        _builder.append(".");
070        Repository _repository_1 = it.getRepository();
071        DomainObject _aggregateRoot_1 = _repository_1.getAggregateRoot();
072        String _name = _aggregateRoot_1.getName();
073        _builder.append(_name, "");
074        _builder.append("Mapper.getInstance());");
075        _builder.newLineIfNotEmpty();
076        _builder.append("ao.setAdditionalDataMappers(getAdditionalDataMappers());");
077        _builder.newLine();
078      }
079    }
080    return _builder.toString();
081  }
082  
083  public AccessObjectFactoryTmpl[] _getOverridesDispatchArray() {
084    org.sculptor.generator.template.repository.AccessObjectFactoryTmpl[] result = new org.sculptor.generator.template.repository.AccessObjectFactoryTmpl[org.sculptor.generator.template.repository.AccessObjectFactoryTmplMethodIndexes.NUM_METHODS];
085    result[org.sculptor.generator.template.repository.AccessObjectFactoryTmplMethodIndexes.FACTORYMETHODINIT_REPOSITORYOPERATION] = this; 
086    return result;
087  }
088}