Commit 8a20fa60 authored by michael.simon's avatar michael.simon
Browse files

first commit of a reverse dto mapper

parent 05f2f679
......@@ -24,11 +24,6 @@ public abstract class AbstractBaseEntityMapper<T extends BaseEntity<PK>,E extend
toDtoEntity.setId(fromBaseEntity.getId());
if ((fromBaseEntity instanceof AbstractBaseEntity)
&& (toDtoEntity instanceof AbstractBaseEntityDto)) {
// AbstractBaseEntity f = (AbstractBaseEntity) fromBaseEntity;
// AbstractBaseEntityDto t = (AbstractBaseEntityDto) toDtoEntity;
// t.setCreatedAt(f.getCreatedAt());
// t.setUpdatedAt(f.getUpdatedAt());
// t.setVersion(f.getVersion());
copy(fromBaseEntity, toDtoEntity, "createdAt", "updatedAt", "version");
}
......
package edu.kit.scc.webreg.dto.mapper;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.PropertyUtils;
import edu.kit.scc.webreg.dto.entity.BaseEntityDto;
import edu.kit.scc.webreg.entity.BaseEntity;
public abstract class AbstractBaseReverseEntityMapper<E extends BaseEntityDto<PK>, T extends BaseEntity<PK>, PK extends Serializable>
implements BaseReverseEntityMapper<E, T, PK>, Serializable {
private static final long serialVersionUID = 1L;
protected abstract void copyAllProperties(E fromBaseEntity, T toDtoEntity);
protected String[] getPropertiesToCopy() {
return new String[]{};
}
@Override
public void copyProperties(E fromBaseEntity, T toDtoEntity) {
copy(fromBaseEntity, toDtoEntity, getPropertiesToCopy());
copyAllProperties(fromBaseEntity, toDtoEntity);
}
protected void copy(E fromBaseEntity, T toDtoEntity, String... props) {
for (String prop : props) {
try {
Object o = PropertyUtils.getProperty(fromBaseEntity, prop);
PropertyUtils.setProperty(toDtoEntity, prop, o);
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {
}
}
}
}
package edu.kit.scc.webreg.dto.mapper;
import java.io.Serializable;
import edu.kit.scc.webreg.dto.entity.BaseEntityDto;
import edu.kit.scc.webreg.entity.BaseEntity;
public interface BaseReverseEntityMapper<E extends BaseEntityDto<PK>, T extends BaseEntity<PK>, PK extends Serializable> {
public void copyProperties(E fromBaseEntity, T toDtoEntity);
}
package edu.kit.scc.webreg.dto.mapper;
import java.util.HashMap;
import java.util.HashSet;
import javax.enterprise.context.ApplicationScoped;
import edu.kit.scc.webreg.dto.entity.ExternalUserEntityDto;
import edu.kit.scc.webreg.entity.ExternalUserEntity;
@ApplicationScoped
public class ExternalUserReverseEntityMapper extends AbstractBaseReverseEntityMapper<ExternalUserEntityDto, ExternalUserEntity, Long> {
private static final long serialVersionUID = 1L;
@Override
protected void copyAllProperties(ExternalUserEntityDto fromBaseEntity, ExternalUserEntity toDtoEntity) {
if (fromBaseEntity.getEmailAddresses() != null) {
toDtoEntity.setEmailAddresses(new HashSet<String>());
toDtoEntity.getEmailAddresses().addAll(fromBaseEntity.getEmailAddresses());
}
if (fromBaseEntity.getAttributeStore() != null) {
toDtoEntity.setAttributeStore(new HashMap<String, String>());
toDtoEntity.getAttributeStore().putAll(fromBaseEntity.getAttributeStore());
}
if (fromBaseEntity.getGenericStore() != null) {
toDtoEntity.setGenericStore(new HashMap<String, String>());
toDtoEntity.getGenericStore().putAll(fromBaseEntity.getGenericStore());
}
}
@Override
protected String[] getPropertiesToCopy() {
return new String[] {"externalId", "eppn", "emailAddress",
"givenName", "surName", "uidNumber"};
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment