Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
templates.Service.xpt Maven / Gradle / Ivy
?IMPORT dom?
?IMPORT core?
?EXTENSION extensions::EntityExtension?
?EXTENSION extensions::ServiceExtension?
?EXTENSION extensions::File?
?EXTENSION extensions::JavaUtil?
?EXTENSION extensions::Names?
?EXTENSION extensions::Properties?
?EXTENSION org::eclipse::xtend::util::stdlib::collections?
?EXTENSION org::openxma::dsl::common::extensions::LogUtil?
/**
* main entry point for services generator
*/
?DEFINE main FOR Model?
?EXPAND genInterface FOREACH eAllContents.typeSelect(Service)?
?EXPAND manInterface FOREACH eAllContents.typeSelect(Service)?
?EXPAND genClass FOREACH eAllContents.typeSelect(Service)?
?EXPAND manClass FOREACH eAllContents.typeSelect(Service)?
?ENDDEFINE?
/**
* Generates an interface for the given service
*/
?DEFINE genInterface FOR Service?
?info("Write "+getGenInterfaceFileName())?
?FILE getGenInterfaceFileName()-?
package ?getPackageName(false)?;
?addImports()-?
?EXPAND manImportsImpl FOR this-?
?EXPAND Documentation::documentation FOR this-?
?EXPAND genInterfaceAnnotation FOR this-?
public interface ?getGenInterfaceName()? {
?FOREACH operations AS operation-?
?EXPAND Features::operationSignature(false) FOR operation-?;
?ENDFOREACH-?
?LET (List[Operation])getCreateUpdateOperations(operations) AS createUpdateOperations-?
?FOREACH createUpdateOperations AS op-?
?op.delegate.view.name? saveOrUpdate(?op.delegate.viewParameter.name? ?op.delegate.viewParameter.name.toFirstLower()?);
?ENDFOREACH-?
?ENDLET-?
?EXPAND genOperationInterface FOR this-?
}
?ENDFILE-?
?ENDDEFINE?
/**
* Generates a manual interface for the given service
*/
?DEFINE manInterface FOR Service?
?info("Write "+getInterfaceFileName())?
?FILE getInterfaceFileName() OUTLET_JAVA-?
package ?getPackageName(false)?;
?EXPAND Documentation::documentation FOR this-?
public interface ?name? extends ?getGenInterfaceName()? {
?EXPAND manOperationInterface FOR this-?
}
?ENDFILE-?
?ENDDEFINE?
/**
* defines a hook for generating additional annotation in the GENERATED repository INTERFACE
*/
?DEFINE genInterfaceAnnotation FOR Service-??ENDDEFINE?
/**
* defines a hook for generating additional imports in the GENERATED repository IMPLEMENTATION
*/
?DEFINE genImportsImpl FOR Service??ENDDEFINE?
/**
* defines a hook for generating additional imports in the MANUAL repository IMPLEMENTATION
*/
?DEFINE manImportsImpl FOR Service??ENDDEFINE?
/**
* defines a hook for generating additional operations for the GENERATED service INTERFACE
*/
?DEFINE genOperationInterface FOR Service??ENDDEFINE?
/**
* defines a hook for generating additional operations for the GENERATED service IMPLEMENTATION
*/
?DEFINE genOperationImpl FOR Service??ENDDEFINE?
/**
* defines a hook for generating additional operations for the MANUAL service INTERFACE
*/
?DEFINE manOperationInterface FOR Service??ENDDEFINE?
/**
* defines a hook for generating additional operations for the MANUAL service IMPLEMENTATION
*/
?DEFINE manOperationImpl FOR Service??ENDDEFINE?
/**
* dependency member declaration
*/
?DEFINE dependency FOR Dependant??ENDDEFINE?
?DEFINE dependency FOR Service-?
protected ?name? ?getQualifiedInterfaceName().toFirstLower()?;
?ENDDEFINE??DEFINE dependency FOR Dao-?
protected ?name? ?getQualifiedInterfaceName().toFirstLower()?;
?ENDDEFINE?
/**
* dependency setter
*/
?DEFINE dependencySetter FOR Dependant??ENDDEFINE?
?DEFINE dependencySetter FOR Service?
@Autowired
public void set?name?(?getName(false)? ?name.toFirstLower()?) {
this.?name.toFirstLower()? = ?name.toFirstLower()?;
}
?ENDDEFINE?
?DEFINE dependencySetter FOR Dao?
@Autowired
public void set?name?(?name? ?name.toFirstLower()?) {
this.?name.toFirstLower()? = ?name.toFirstLower()?;
}
?ENDDEFINE?
/**
* Generates an implementation class for the given service
*/
?DEFINE genClass FOR Service?
?LET !operations.isEmpty AS isAbstractService?
?info("Write "+getGenClassFileName())?
?FILE getGenClassFileName()-?
package ?getPackageName(true)?;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openxma.dsl.platform.service.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
?addImports()-?
?EXPAND genImportsImpl FOR this-?
?EXPAND Documentation::documentation FOR this-?
public abstract class ?getGenClassName()? ?IF getServiceBaseClass().trim()!=""?extends ?registerImport(getServiceBaseClass())? ?ENDIF?implements ?getQualifiedInterfaceName()? {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired(required=false)
protected Mapper mapper;
?EXPAND dependency FOREACH dependencies-?
?EXPAND dependencySetter FOREACH dependencies-?
?FOREACH operations.select(e|e.delegate.crudOperationType!=null && e.delegate.crudOperationType!=CrudOperationType::NULL && e.delegate.crudOperationType!=CrudOperationType::ALL) AS crudOperation-?
?EXPAND crudOperationImplementation(crudOperation.delegate.crudOperationType,crudOperation.delegate.repository,crudOperation.delegate.viewParameter) FOR crudOperation-?
?ENDFOREACH-?
?LET (List[Operation])getCreateUpdateOperations(operations) AS createUpdateOperations-?
?FOREACH createUpdateOperations AS op-?
?IF op.delegate.repository.entity.version != null || op.delegate.repository.entity.identifier != null -?
?EXPAND crudSaveOrUpdateImplementation(op.delegate.repository,op.delegate.view,op.delegate.viewParameter) FOR op-?
?ENDIF?
?ENDFOREACH-?
?ENDLET-?
?FOREACH operations.select(e|DaoOperation.isInstance(e.delegate.operation)) AS queryOperation-?
?EXPAND queryOperationImplementation FOR queryOperation?
?ENDFOREACH-?
?EXPAND genOperationImpl FOR this-?
}
?ENDFILE-?
?ENDLET?
?ENDDEFINE?
/**
* Generates a manual implementation class for the given service
*/
?DEFINE manClass FOR Service?
?LET !operations.isEmpty AS isAbstractService?
?info("Write "+getClassFileName())?
?FILE getClassFileName() OUTLET_JAVA-?
package ?getPackageName(true)?;
import org.springframework.stereotype.Service;
?addImports()-?
?EXPAND Documentation::documentation FOR this-?
@Service("?name.toFirstLower()?")
public class ?getClassName()? extends ?getQualifiedGenClassName()? {
?FOREACH operations.select(e|e.delegate==null) AS operation-?
?EXPAND Features::operationSignature(true) FOR operation-? {
// TODO
throw new IllegalStateException("not yet implemented");
}
?ENDFOREACH-?
?EXPAND manOperationImpl FOR this-?
}
?ENDFILE-?
?ENDLET?
?ENDDEFINE?
?DEFINE crudSaveOrUpdateImplementation(Dao repository,DataView view,DataView viewParameter) FOR Operation?
@?registerImport("org.springframework.transaction.annotation.Transactional")?
public ?view.name? saveOrUpdate(?viewParameter.name? ?viewParameter.name.toFirstLower()?) {
?registerImport("org.springframework.util.Assert")?.notNull(?viewParameter.name.toFirstLower()?, "parameter '?viewParameter.name.toFirstLower()?' must not be null");
?IF repository.entity.version != null-?
if ( ?viewParameter.name.toFirstLower()?.?repository.entity.version.getAccessorMethodName()?() == null ) {
?ELSE-?
if ( ?viewParameter.name.toFirstLower()?.?repository.entity.identifier.getAccessorMethodName()?() == null ) {
?ENDIF-?
return this.save(?viewParameter.name.toFirstLower()?);
}
else {
this.update(?viewParameter.name.toFirstLower()?);
?IF view == viewParameter-?
return ?viewParameter.name.toFirstLower()?;
?ELSE-?
?IF repository.entity.identifier!=null-?
?repository.entity.getQualifiedInterfaceName()? mapped?repository.entity.name? = this.mapper.createAndMapOne(?viewParameter.name.toFirstLower()?, ?repository.entity.name?.class);
?repository.entity.name? ?repository.entity.name.toVariableName()? = this.?repository.name.toFirstLower()?.load(mapped?repository.entity.name?.?repository.entity.identifier.getAccessorMethodName()?());
?ELSE-?
?repository.entity.getQualifiedInterfaceName()? ?repository.entity.name.toVariableName()? = this.?repository.name.toFirstLower()?.?repository.naturalKey.getMethodName()?(?FOREACH repository.entity.key.attributes.attribute AS field SEPARATOR ","??viewParameter.name.toFirstLower()?.?field.getAccessorMethodName()?()?ENDFOREACH?);
?ENDIF-?
this.mapper.mapOne(?viewParameter.name.toFirstLower()?, ?repository.entity.name.toVariableName()?,"update?repository.entity.name?");
return this.mapper.createAndMapOne(?repository.entity.name.toVariableName()?,?view.name?.class);
?ENDIF-?
}
}
?ENDDEFINE?
?DEFINE crudOperationImplementation(CrudOperationType crudOperationType,Dao repository,DataView viewParameter) FOR Operation?
?IF crudOperationType==CrudOperationType::CREATE-?
?LET viewParameter.featureReferences.select(e|e.source==repository.entity && e.attribute.reference && e.attribute.many && e.view.includesAllRequiredFeaturesFor(((Entity)e.attribute.dataType))) AS toManyReferences-?
?LET (List[Attribute]){} AS views-?
@?registerImport("org.springframework.transaction.annotation.Transactional")?
?EXPAND Features::operationSignature(true)-? {
?registerImport("org.springframework.util.Assert")?.notNull(?viewParameter.name.toFirstLower()?, "parameter '?viewParameter.name.toFirstLower()?' must not be null");
?repository.entity.getQualifiedInterfaceName()? ?repository.entity.name.toVariableName()? = this.mapper.createAndMapOne(?viewParameter.name.toFirstLower()?, ?repository.entity.name?.class,"save?repository.entity.name?");
?FOREACH repository.entity.requiredReferences AS requiredReference-?
?requiredReference.getImplementationType()? ?requiredReference.name.toFirstLower()? = this.mapper.createAndMapOne(?viewParameter.name.toFirstLower()?, ?requiredReference.dataType.name?.class,"?requiredReference.name?");
?LET ((Entity)requiredReference.dataType) AS requiredEntity-?
?IF requiredEntity.identifier!=null-?
?requiredReference.name.toFirstLower()? = ?requiredEntity.repository.name.toFirstLower()?.load(?requiredReference.name.toFirstLower()?.?requiredEntity.identifier.getAccessorMethodName()?());
?ELSE-?
?requiredReference.name.toFirstLower()? = ?requiredEntity.repository.name.toFirstLower()?.load(?requiredReference.name.toFirstLower()?.?requiredEntity.key.getAccessorMethodName()?());
?ENDIF-?
?repository.entity.name.toVariableName()?.?requiredReference.getMutatorMethodName()?(?requiredReference.name.toFirstLower()?);
?ENDLET-?
?ENDFOREACH-?
?FOREACH ((List[Attribute]) getAllNonRequiredReferenceNonManyAttributesRecursive(repository.entity)) AS optionalReference-?
?IF viewParameter.featureReferences.exists(e|e.attribute == optionalReference)-?
?LET viewParameter.featureReferences.selectFirst(e|e.attribute == optionalReference) AS theTarget-?
if (null != ?viewParameter.name.toFirstLower()?.?theTarget.getAccessorMethodName()?()) {
?optionalReference.getImplementationType()? optional?optionalReference.name.toFirstUpper()? = this.mapper.createAndMapOne(?viewParameter.name.toFirstLower()?.?theTarget.getAccessorMethodName()?(), ?optionalReference.dataType.name?.class,"?optionalReference.name?");
?LET ((Entity)optionalReference.dataType) AS optionalEntity-?
?IF optionalEntity.identifier!=null-?
optional?optionalReference.name.toFirstUpper()? = ?optionalEntity.repository.name.toFirstLower()?.load(optional?optionalReference.name.toFirstUpper()?.?optionalEntity.identifier.getAccessorMethodName()?());
?ELSE-?
optional?optionalReference.name.toFirstUpper()? = ?optionalEntity.repository.name.toFirstLower()?.load(optional?optionalReference.name.toFirstUpper()?.?optionalEntity.key.getAccessorMethodName()?());
?ENDIF-?
?repository.entity.name.toVariableName()?.?optionalReference.getMutatorMethodName()?(optional?optionalReference.name.toFirstUpper()?);
?ENDLET-?
}
?ENDLET-?
?ENDIF-?
?ENDFOREACH-?
?FOREACH toManyReferences AS includedFeature-?
add?includedFeature.attribute.name.toFirstUpper()?(?repository.entity.name.toVariableName()?,?viewParameter.name.toFirstLower()?);
?ENDFOREACH-?
this.?repository.name.toFirstLower()?.saveOrUpdate(?repository.entity.name.toVariableName()?);
return this.mapper.mapOne(?repository.entity.name.toVariableName()?,new ?type.name?());
}
?FOREACH toManyReferences AS includedFeature-?
?EXPAND addReference(viewParameter,views) FOR includedFeature-?
?ENDFOREACH-?
?ENDLET-?
?ENDLET-?
?ENDIF-?
?IF crudOperationType==CrudOperationType::READ-?
?IF repository.entity.identifier!=null-?
@?registerImport("org.springframework.transaction.annotation.Transactional")?(readOnly = true)
?EXPAND Features::operationSignature(true)-? {
?registerImport("org.springframework.util.Assert")?.notNull(?repository.entity.identifier.name?, "parameter '?repository.entity.identifier.name?' must not be null");
return this.mapper.createAndMapOne(this.?repository.name.toFirstLower()?.load(?repository.entity.identifier.name?),?type.name?.class);
}
?ELSE-?
@?registerImport("org.springframework.transaction.annotation.Transactional")?(readOnly = true)
?EXPAND Features::operationSignature(true)-? {
?FOREACH repository.entity.key.attributes.attribute AS field-?
?registerImport("org.springframework.util.Assert")?.notNull(?field.name?, "parameter '?field.name?' must not be null");
?ENDFOREACH-?
return this.mapper.createAndMapOne(this.?repository.name.toFirstLower()?.load(new ?repository.entity.getFullyQualifiedCompositeIdentifierName()?(?FOREACH repository.entity.key.attributes.attribute AS field SEPARATOR ","??field.name??ENDFOREACH?)),?type.name?.class);
}
?ENDIF-?
?ENDIF-?
?IF crudOperationType==CrudOperationType::UPDATE-?
@?registerImport("org.springframework.transaction.annotation.Transactional")?
?EXPAND Features::operationSignature(true)-? {
?registerImport("org.springframework.util.Assert")?.notNull(?viewParameter.name.toFirstLower()?, "parameter '?viewParameter.name.toFirstLower()?' must not be null");
?IF repository.entity.identifier!=null-?
?repository.entity.getQualifiedInterfaceName()? mapped?repository.entity.name? = this.mapper.createAndMapOne(?viewParameter.name.toFirstLower()?, ?repository.entity.name?.class);
?repository.entity.name? ?repository.entity.name.toVariableName()? = this.?repository.name.toFirstLower()?.load(mapped?repository.entity.name?.?repository.entity.identifier.getAccessorMethodName()?());
?IF repository.entity.version!=null && viewParameter.includesVersion(repository.entity)-?
if (!?repository.entity.name.toVariableName()?.?repository.entity.version.getAccessorMethodName()?().equals(mapped?repository.entity.name?.?repository.entity.version.getAccessorMethodName()?())) {
throw new ?registerImport("org.springframework.dao.OptimisticLockingFailureException")?("Entity '?repository.entity.name?' was updated or deleted by another transaction.");
}
?ENDIF-?
?ELSE-?
?repository.entity.getQualifiedInterfaceName()? ?repository.entity.name.toVariableName()? = this.?repository.name.toFirstLower()?.?repository.naturalKey.getMethodName()?(?FOREACH repository.entity.key.attributes.attribute AS field SEPARATOR ","??viewParameter.name.toFirstLower()?.?field.getAccessorMethodName()?()?ENDFOREACH?);
?ENDIF-?
this.mapper.mapOne(?viewParameter.name.toFirstLower()?, ?repository.entity.name.toVariableName()?,"update?repository.entity.name?");
}
?ENDIF-?
?IF crudOperationType==CrudOperationType::DELETE-?
?IF repository.entity.identifier!=null-?
@?registerImport("org.springframework.transaction.annotation.Transactional")?
?EXPAND Features::operationSignature(true)-? {
?registerImport("org.springframework.util.Assert")?.notNull(?repository.entity.identifier.name?, "parameter '?repository.entity.identifier.name?' must not be null");
this.?repository.name.toFirstLower()?.delete(?repository.entity.identifier.name?);
}
?ELSE-?
@?registerImport("org.springframework.transaction.annotation.Transactional")?
public void delete?repository.entity.name?(?EXPAND Features::methodParameter FOREACH repository.entity.key.attributes.attribute SEPARATOR ","?) {
?FOREACH repository.entity.key.attributes.attribute AS field-?
?registerImport("org.springframework.util.Assert")?.notNull(?field.name?, "parameter '?field.name?' must not be null");
?ENDFOREACH-?
this.?repository.name.toFirstLower()?.delete(new ?repository.entity.getFullyQualifiedCompositeIdentifierName()?(?FOREACH repository.entity.key.attributes.attribute AS field SEPARATOR ","??field.name??ENDFOREACH?));
}
?ENDIF-?
?ENDIF-?
?ENDDEFINE?
?DEFINE queryOperationImplementation FOR Operation-?
@?registerImport("org.springframework.transaction.annotation.Transactional")??IF delegate!=null && QueryOperation.isInstance(delegate.operation) && SelectStatement.isInstance(((QueryOperation)delegate.operation).statement)?(readOnly=true)?ENDIF?
?EXPAND Features::operationSignature(true)-? {
?IF delegate.filter!=null && QueryOperation.isInstance(delegate.operation) && parameters.last().name=="_filter"-?
?registerImport("org.openxma.dsl.platform.query.QueryObject")? queryObject = QueryObject.createNamedQuery(?((QueryOperation)delegate.operation).getDaoConstantName()?, _filter);
?FOREACH ((QueryOperation)delegate.operation).queryParameters.reject(e|Parameter.isInstance(e) && (((Parameter)e).name=="firstResult" || ((Parameter)e).name=="maxResults")) AS parameter ITERATOR iter-?
?LET delegate.operation.eAllContents.typeSelect(QueryParameterValue).selectFirst(e|e.parameter==parameter || e.parameter==parameter.attribute) AS queryParameterValue-?
?IF queryParameterValue != null-?
?IF ComplexType.isInstance(parameter.getParameterType()) && queryParameterValue.attribute!=null-?
?FOREACH delegate.operation.eAllContents.typeSelect(QueryParameterValue).select(e|e.parameter==parameter).attribute.toSet().sortBy(e|e.name) AS attribute-?
queryObject.withArgs("?parameter.getName()?_?attribute.name?", ?parameter.getName()?.?attribute.getAccessorMethodName()?());
?ENDFOREACH-?
?ELSE-?
queryObject.withArgs("?parameter.getName()?", ?parameter.getName()?);
?ENDIF-?
?ENDIF-?
?ENDLET-?
?ENDFOREACH-?
?delegate.operation.getType()? _result = this.?delegate.repository.name.toFirstLower()?.query(queryObject);
?IF delegate.view!=null-?
return this.mapper.createAndMapMany(_result,?delegate.view.getFullyQualifiedName(true)?.class);
?ELSE-?
return _result;
?ENDIF-?
?ELSE-?
?IF delegate.view!=null-?
return this.mapper.?IF many?createAndMapMany?ELSE?createAndMapOne?ENDIF?(this.?delegate.repository.name.toFirstLower()?.?delegate.operation.name?(?FOREACH parameters AS parameter SEPARATOR ","??IF parameter.hasProperty("entity")?mapper.createAndMapOne(?parameter.name.toFirstLower()?,?((Entity)parameter.getProperty('entity')).getFullyQualifiedName(false)?.class)?ELSE??parameter.name.toFirstLower()??ENDIF??ENDFOREACH-?),?delegate.view.getFullyQualifiedName(true)?.class);
?ELSE-?
?IF type!=null?return ?ENDIF?this.?delegate.repository.name.toFirstLower()?.?delegate.operation.name?(?FOREACH parameters AS parameter SEPARATOR ","??IF parameter.hasProperty("entity")?mapper.createAndMap?IF parameter.many?Many?ELSE?One?ENDIF?(?parameter.name.toFirstLower()?,?((Entity)parameter.getProperty('entity')).getFullyQualifiedName(false)?.class)?ELSE??parameter.name.toFirstLower()??ENDIF??ENDFOREACH?);
?ENDIF-?
?ENDIF-?
}
?ENDDEFINE?
?DEFINE addReference(DataView parentView,List[Attribute] views) FOR FeatureReference-?
?IF !views.contains(attribute)-?
?views.add(attribute) -> ""?
private void add?attribute.name.toFirstUpper()?(?source.getFullyQualifiedName(false)? parent?source.name?,?parentView.getFullyQualifiedName(false)? ?parentView.name.toFirstLower()?) {
if (?parentView.name.toFirstLower()?.?attribute.getAccessorMethodName()?() != null) {
for (?view.getFullyQualifiedName(true)? _?view.name.toFirstLower()? : ?parentView.name.toFirstLower()?.?attribute.getAccessorMethodName()?()) {
?attribute.getImplementationType()? ?attribute.dataType.name.toFirstLower()? = this.mapper.createAndMapOne(_?view.name.toFirstLower()?, ?attribute.getImplementationType()?.class,"save?attribute.dataType.name?");
?FOREACH ((Entity)attribute.dataType).requiredReferences.select(e|e.opposite!=attribute && attribute.opposite!=e) AS requiredReference-?
?requiredReference.getImplementationType()? ?requiredReference.name.toFirstLower()? = this.mapper.createAndMapOne(_?view.name.toFirstLower()?, ?requiredReference.getImplementationType()?.class,"?requiredReference.name?");
if (?requiredReference.name.toFirstLower()?.?((Entity)requiredReference.dataType).identifier.getAccessorMethodName()?() != null) {
?LET ((Entity)requiredReference.dataType) AS requiredEntity-?
?requiredReference.name.toFirstLower()? = ?requiredEntity.repository.name.toFirstLower()?.load(?requiredReference.name.toFirstLower()?.?requiredEntity.identifier.getAccessorMethodName()?());
?attribute.dataType.name.toFirstLower()?.?requiredReference.getMutatorMethodName()?(?requiredReference.name.toFirstLower()?);
?ENDLET-?
}
?ENDFOREACH-?
?FOREACH view.featureReferences.select(e|e.attribute.reference && !views.contains(e.attribute) && e.attribute.many && e.view.includesAllRequiredFeaturesFor(((Entity)e.attribute.dataType))) AS nestedIncludedFeature-?
add?nestedIncludedFeature.attribute.name.toFirstUpper()?(?attribute.dataType.name.toFirstLower()?,_?view.name.toFirstLower()?);
?ENDFOREACH-?
parent?source.name?.?attribute.getAddMethodName()?(?attribute.dataType.name.toFirstLower()?);
}
}
}
?FOREACH view.featureReferences.select(e|e.view!=null && e.attribute.many && e.view.includesAllRequiredFeaturesFor(((Entity)e.attribute.dataType))) AS includedFeature-?
?EXPAND addReference(view,views) FOR includedFeature-?
?ENDFOREACH-?
?ENDIF-?
?ENDDEFINE?