1
|
package eu.dnetlib.enabling.utils;
|
2
|
|
3
|
import java.util.Date;
|
4
|
|
5
|
import org.apache.commons.lang.StringUtils;
|
6
|
|
7
|
import eu.dnetlib.enabling.annotations.DnetResource;
|
8
|
import eu.dnetlib.rmi.objects.is.DnetDataStructure;
|
9
|
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException;
|
10
|
|
11
|
public class DnetResourceFactory {
|
12
|
|
13
|
public static DnetDataStructure createDatastructure(final String code, final String name, final Object contentObj) throws InformationServiceException {
|
14
|
if (contentObj == null) {
|
15
|
throw new InformationServiceException("contentObj is null");
|
16
|
} else if (contentObj.getClass().isAnnotationPresent(DnetResource.class)) {
|
17
|
throw new InformationServiceException("Missing DnetResource annotation in class " + contentObj.getClass());
|
18
|
} else if (StringUtils.isBlank(code)) {
|
19
|
throw new InformationServiceException("Code is empty for contentObj: " + contentObj);
|
20
|
} else {
|
21
|
final DnetDataStructure ds = new DnetDataStructure();
|
22
|
ds.setCode(code);
|
23
|
ds.setName(name);
|
24
|
ds.setType(contentObj.getClass().getAnnotation(DnetResource.class).type());
|
25
|
ds.setDate(new Date());
|
26
|
ds.setContentFromObject(contentObj);
|
27
|
return ds;
|
28
|
}
|
29
|
}
|
30
|
}
|