org.joinedworkz.common.strategies.DtoFieldNameStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-base Show documentation
Show all versions of common-base Show documentation
DSL based modeling framework - facilities common base
package org.joinedworkz.common.strategies;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.xtext.xbase.lib.Extension;
import org.joinedworkz.common.helper.CmnModelHelper;
import org.joinedworkz.common.helper.Inflector;
import org.joinedworkz.common.helper.NameHelper;
import org.joinedworkz.core.facility.AbstractStrategy;
import org.joinedworkz.core.model.CmnField;
import org.joinedworkz.core.model.CmnObject;
@Singleton
@SuppressWarnings("all")
public class DtoFieldNameStrategy extends AbstractStrategy {
@Inject
@Extension
private NameHelper _nameHelper;
@Inject
@Extension
private CmnModelHelper _cmnModelHelper;
@Inject
private Inflector inflector;
@Override
public String apply(final CmnObject obj) {
if ((obj instanceof CmnField)) {
return this.dtoFieldName(((CmnField)obj));
}
return null;
}
protected String dtoFieldName(final CmnField field) {
final String fieldName = this._cmnModelHelper.javaName(field);
boolean _isReferenceField = this._cmnModelHelper.isReferenceField(field);
if (_isReferenceField) {
CmnField _sourceField = field.getSourceField();
boolean _tripleNotEquals = (_sourceField != null);
if (_tripleNotEquals) {
final String sourceFieldJavaName = this._cmnModelHelper.sourceFieldJavaNameRecursive(field);
boolean _notEquals = (!Objects.equals(fieldName, sourceFieldJavaName));
if (_notEquals) {
return fieldName;
}
}
return this.dtoReferenceFieldName(fieldName, field);
} else {
return fieldName;
}
}
protected String dtoReferenceFieldName(final String fieldName, final CmnField field) {
final String keyName = this._cmnModelHelper.keyJavaName(field.getType());
boolean _isCollection = this._cmnModelHelper.isCollection(field);
if (_isCollection) {
final String singularFieldName = this.inflector.singularize(fieldName);
String _xifexpression = null;
if ((keyName != null)) {
_xifexpression = this.inflector.pluralize(keyName);
} else {
_xifexpression = null;
}
final String pluralKeyName = _xifexpression;
return this.composeNameParts(singularFieldName, pluralKeyName);
} else {
return this.composeNameParts(fieldName, keyName);
}
}
protected String composeNameParts(final String fieldName, final String keyName) {
String _firstUpper = null;
if (keyName!=null) {
_firstUpper=this._nameHelper.toFirstUpper(keyName);
}
return (fieldName + _firstUpper);
}
}