use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class EntityServiceImpl method convertToGenericEntity.
public Entity convertToGenericEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity, final Entity performer) {
Entity genericEntity = null;
if (databaseEntity instanceof Object[]) {
genericEntity = dataDefinition.create();
Object[] databaseArray = (Object[]) databaseEntity;
List<String> fields = new ArrayList<String>(dataDefinition.getFields().keySet());
for (int i = 0; i < fields.size(); i++) {
if (dataDefinition.getField(fields.get(i)).getType() instanceof BelongsToType) {
InternalDataDefinition referencedDataDefinition = (InternalDataDefinition) ((BelongsToType) dataDefinition.getField(fields.get(i)).getType()).getDataDefinition();
genericEntity.setField(fields.get(i), convertToGenericEntity(referencedDataDefinition, databaseArray[i]));
} else {
genericEntity.setField(fields.get(i), databaseArray[i]);
}
}
} else if (databaseEntity.getClass().getName().startsWith("com.qcadoo.model.beans")) {
genericEntity = dataDefinition.create(getId(databaseEntity));
if (dataDefinition.isActivable()) {
genericEntity.setActive(getActive(databaseEntity));
}
for (Entry<String, FieldDefinition> fieldDefinitionEntry : dataDefinition.getFields().entrySet()) {
if (fieldDefinitionEntry.getValue().isPersistent() && ((InternalFieldDefinition) fieldDefinitionEntry.getValue()).isEnabled()) {
Entity currentPerformer = performer;
if (currentPerformer == null) {
currentPerformer = genericEntity;
}
genericEntity.setField(fieldDefinitionEntry.getKey(), getField(databaseEntity, fieldDefinitionEntry.getValue(), currentPerformer));
}
}
if (dataDefinition.isPrioritizable()) {
genericEntity.setField(dataDefinition.getPriorityField().getName(), getField(databaseEntity, dataDefinition.getPriorityField()));
}
for (Entry<String, FieldDefinition> fieldDefinitionEntry : dataDefinition.getFields().entrySet()) {
if (fieldDefinitionEntry.getValue().getExpression() != null && ((InternalFieldDefinition) fieldDefinitionEntry.getValue()).isEnabled()) {
genericEntity.setField(fieldDefinitionEntry.getKey(), expressionService.getValue(genericEntity, fieldDefinitionEntry.getValue().getExpression(), Locale.ENGLISH));
}
}
dataDefinition.callViewHook(genericEntity);
} else {
genericEntity = new DefaultEntity(dataDefinition);
genericEntity.setField(dataDefinition.getFields().keySet().iterator().next(), databaseEntity);
}
return genericEntity;
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class EntityServiceImpl method getHasManyField.
private Object getHasManyField(final Object databaseEntity, final FieldDefinition fieldDefinition) {
Long parentId = getId(databaseEntity);
HasManyType hasManyFieldType = (HasManyType) fieldDefinition.getType();
InternalDataDefinition referencedDataDefinition = (InternalDataDefinition) hasManyFieldType.getDataDefinition();
return new EntityListImpl(referencedDataDefinition, hasManyFieldType.getJoinFieldName(), parentId);
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class ModelXmlToDefinitionConverterTest method init.
@BeforeClass
public static void init() throws Exception {
applicationContext = mock(ApplicationContext.class);
dataAccessService = mock(DataAccessService.class);
translationService = mock(TranslationService.class);
dataDefinitionService = new DataDefinitionServiceImpl();
modelXmlToDefinitionConverter = new ModelXmlToDefinitionConverterImpl();
setField(modelXmlToDefinitionConverter, "dataDefinitionService", dataDefinitionService);
setField(modelXmlToDefinitionConverter, "dataAccessService", dataAccessService);
setField(modelXmlToDefinitionConverter, "applicationContext", applicationContext);
setField(modelXmlToDefinitionConverter, "translationService", translationService);
given(applicationContext.getBean(CustomHook.class)).willReturn(new CustomHook());
modelXmlToClassConverter = new ModelXmlToClassConverterImpl();
((ModelXmlToClassConverterImpl) modelXmlToClassConverter).setBeanClassLoader(ClassLoader.getSystemClassLoader());
dataDefinitions = performConvert(Utils.FULL_FIRST_ENTITY_XML_RESOURCE, Utils.FULL_SECOND_ENTITY_XML_RESOURCE, Utils.FULL_THIRD_ENTITY_XML_RESOURCE, Utils.OTHER_FIRST_ENTITY_XML_RESOURCE, Utils.OTHER_SECOND_ENTITY_XML_RESOURCE);
for (DataDefinition dd : dataDefinitions.toArray(new DataDefinition[dataDefinitions.size()])) {
if (dd.getName().equals("firstEntity") && dd.getPluginIdentifier().equals("full")) {
dataDefinition = (InternalDataDefinition) dd;
}
}
}
Aggregations