Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.0.0
-
Fix Version/s: 1.1.0
-
Component/s: None
-
Labels:None
-
Environment:SmartJava CompCompas project.
-
Number of attachments :
Description
Given following dsl's:
DomainModel
Class Medewerker [
string naam;
]
Association medewerkers Medewerker [ 0..* ] -> [ 1 ] manager Medewerker ;
DataContractModel
BusinessClassDto MedewerkerDto base Medewerker [
naam ;
references [
manager as MedewerkerDto ;
]
]
ServiceModel
crud for MedewerkerDto ;
The MedewerkerDtoTranslator is generated as followed:
/**
- DO NOT MODIFY THIS FILE, CHANGES WILL BE AUTOMATICALLY OVERWRITTEN
* - Generated by Mod4j DataContract DSL in Translators.xpt at: Thu Feb 26 11:10:54 CET 2009
*/
package nl.ordina.compcompas.service.dto.translators;
import java.util.HashMap;
import java.util.Map;
import org.mod4j.runtime.exception.TranslatorException;
import nl.ordina.compcompas.domain.Medewerker;
import nl.ordina.compcompas.domain.MedewerkerExample;
import nl.ordina.compcompas.service.dto.MedewerkerDto;
import nl.ordina.compcompas.service.dto.FunctieProfielDefinitieStatusDto;
import nl.ordina.compcompas.domain.Medewerker;
import nl.ordina.compcompas.domain.NormProfiel;
/**
- Translator for translating Medewerker businessclass objects from- and to MedewerkerDto data transfer objects.
* - @author generated by Mod4j
*/
public class MedewerkerDtoTranslator {
/**
- Register for translated Medewerker objects
*/
private Map<Medewerker, MedewerkerDto> translated = new HashMap<Medewerker, MedewerkerDto>();
private FunctieProfielDefinitieStatusDtoTranslator profielStatusTranslator = FunctieProfielDefinitieStatusDtoTranslator
.getInstance();
// Protected constructor is sufficient to suppress unauthorized calls to the constructor
protected MedewerkerDtoTranslator() {
}
/**
- SingletonHolder is loaded on the first execution of Singleton.getInstance()
- or the first access to SingletonHolder.INSTANCE , not before.
*/
private static class SingletonHolder { private final static MedewerkerDtoTranslator INSTANCE = new MedewerkerDtoTranslator(); }
public static MedewerkerDtoTranslator getInstance()
{ return SingletonHolder.INSTANCE; }/**
- Translates a MedewerkerDto dto object into a Medewerker business object. All properties in the dto will be mapped to the
- corresponding property in the <code>target</code> businessclass. Association references in the dto
- will not be translated into the <code>target</code> business object.
- If the given <code>target</code> parameter is null, a new business object will be created and returned.
* - @param source The
{@link MedewerkerDto} object to translate.
* @param target The {@link Medewerker} object translated from source.
*
* @return {@link Medewerker}, the resulting businessclass object.
* @throws TranslatorException
*/
public synchronized Medewerker fromDto(final MedewerkerDto source,
Medewerker target) throws TranslatorException {
if (source == null) { throw new TranslatorException( "Argument source is null! Translation of a dto can not be based on a null dto."); }
if (source.getNaam() == null)
throw new TranslatorException(
"Can not translate dto to Medewerker when non-nullable attribute naam is null.");
if (source.getPersoneelsNummer() == null)
throw new TranslatorException(
"Can not translate dto to Medewerker when non-nullable attribute personeelsNummer is null.");
if (target == null) {
if (source.getId() > 0) { throw new TranslatorException( "Can not translate a dto with existng id to a new businessclass object."); }
target = new Medewerker(source.getNaam(), source
.getPersoneelsNummer()
);
}
target.activateValidation(false);
target.setNaam(source.getNaam());
target.setGeboorteDatum(source.getGeboorteDatum());
target.setEmailAdres(source.getEmailAdres());
target.setPersoneelsNummer(source.getPersoneelsNummer());
if (source.getProfielStatus() != null) { target.setProfielStatus(profielStatusTranslator.fromDto(source .getProfielStatus())); }
target.activateValidation(true);
return target;
}
/**
* Translates a Medewerker business object into a MedewerkerDto dto object. Properties and associations in the business object
* will be mapped to the corresponding properties and associations in the dto object.
* To prevent looping while translating biderectional or circulair associations translated objects will be added to the 'translated' register.
*
* @param source The {@link Medewerker} object to translate.
*
* @return MedewerkerDto The {@link MedewerkerDto}object translated from source.
*/
public synchronized MedewerkerDto toDto(final Medewerker source) {
MedewerkerDtoTranslator managerTranslator = MedewerkerDtoTranslator
.getInstance();
NormProfielDtoTranslator normProfielTranslator = NormProfielDtoTranslator
.getInstance();
if (source == null)
{ throw new TranslatorException( "Argument source is null! Translation of a businessclass object can not be based on a null businessclass."); }if (translated.containsKey((source)))
{ return translated.get(source); }MedewerkerDto result = new MedewerkerDto();
result.setId(source.getId());
result.setNaam(source.getNaam());
result.setGeboorteDatum(source.getGeboorteDatum());
result.setEmailAdres(source.getEmailAdres());
result.setPersoneelsNummer(source.getPersoneelsNummer());
result.setProfielStatus(profielStatusTranslator.toDto(source
.getProfielStatus()));
translated.put(source, result);
if (source.getManager() != null)
{ result.setManager(managerTranslator.toDto(source.getManager())); }if (source.getNormProfiel() != null)
{ result.setNormProfiel(normProfielTranslator.toDto(source .getNormProfiel())); }translated.remove(source);
return result;
}
/**
- Translates a MedewerkerDto dto object into a MedewerkerExample Example business object.
- All properties in the dto will be mapped to the
- corresponding property in the <code>target</code> businessclass. Association references in the dto
- will not be translated into the <code>target</code> business object.
* - @param source The
{@link MedewerkerDto}
object to translate.
* - @return
{@link MedewerkerExample}
, the resulting businessclass object.
*/
public MedewerkerExample exampleFromDto(final MedewerkerDto source)
throws TranslatorException {
MedewerkerExample result = new MedewerkerExample();
if (source == null)
{ throw new TranslatorException( "Argument source is null! Translation of a dto can not be based on a null dto."); }if (source.getNaam() != null)
{ result.setNaam(source.getNaam()); }if (source.getGeboorteDatum() != null)
{ result.setGeboorteDatum(source.getGeboorteDatum()); }if (source.getEmailAdres() != null)
{ result.setEmailAdres(source.getEmailAdres()); }if (source.getPersoneelsNummer() != null)
{ result.setPersoneelsNummer(source.getPersoneelsNummer()); }if (source.getProfielStatus() != null)
{ result.setProfielStatus(profielStatusTranslator.fromDto(source .getProfielStatus())); } return result;
}
}
In the toDto method the manager relation is translated, but in the fromDto method the manager is NOT translated.
Issue Links
- depends upon
-
MODFORJ-125
Add toString, equals, etc implementation to Dto'
-
The behavior as described in the intended behavior in the reference architecture. When a business class DTO is updated or created through a (create or update) service method only the attributes of the object are updated.
The reason behind this is that the DTO's are complete detached from the domain model and that it is easily possible to have incorrect and inonsistent object structures at the DTO level. It is very complex to check these, and even harder to give useful error messages back to the caller.
The way to add objects to an association is to use the "reference add" or "reference delete" methods in the service model.
I know that this is a bit cumbersome, but to a certain extent this is a consequence of the chosen SOA architecture.