commonapis.AddressAPI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of db-api Show documentation
Show all versions of db-api Show documentation
EPOS Database APIs useful to interact with EPOS Metadata Catalogue
package commonapis;
import abstractapis.AbstractAPI;
import metadataapis.EntityNames;
import model.Address;
import model.Category;
import model.Identifier;
import org.apache.commons.math3.analysis.function.Add;
import org.epos.eposdatamodel.LinkedEntity;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public class AddressAPI extends AbstractAPI {
public AddressAPI(String entityName, Class> edmClass) {
super(entityName, edmClass);
}
@Override
public LinkedEntity create(org.epos.eposdatamodel.Address obj) {
List returnList = getDbaccess().getOneFromDB(
obj.getInstanceId(),
obj.getMetaId(),
obj.getUid(),
obj.getVersionId(),
getEdmClass());
if(!returnList.isEmpty()){
obj.setInstanceId(returnList.get(0).getInstanceId());
obj.setMetaId(returnList.get(0).getMetaId());
obj.setUid(returnList.get(0).getUid());
obj.setVersionId(returnList.get(0).getVersionId());
}
obj = (org.epos.eposdatamodel.Address) VersioningStatusAPI.checkVersion(obj);
Address edmobj = new Address();
edmobj.setVersionId(obj.getVersionId());
edmobj.setInstanceId(obj.getInstanceId());
edmobj.setMetaId(obj.getMetaId());
edmobj.setUid(Optional.ofNullable(obj.getUid()).orElse(getEdmClass().getSimpleName()+"/"+UUID.randomUUID().toString()));
edmobj.setCountry(Optional.ofNullable(obj.getCountry()).orElse(null));
edmobj.setCountrycode(Optional.ofNullable(obj.getCountryCode()).orElse(null));
edmobj.setStreet(Optional.ofNullable(obj.getStreet()).orElse(null));
edmobj.setPostalCode(Optional.ofNullable(obj.getPostalCode()).orElse(null));
edmobj.setLocality(Optional.ofNullable(obj.getLocality()).orElse(null));
getDbaccess().updateObject(edmobj);
return new LinkedEntity().entityType(entityName)
.instanceId(edmobj.getInstanceId())
.metaId(edmobj.getMetaId())
.uid(edmobj.getUid());
}
@Override
public org.epos.eposdatamodel.Address retrieve(String instanceId) {
Address edmobj = (Address) getDbaccess().getOneFromDBByInstanceId(instanceId, Address.class).get(0);
org.epos.eposdatamodel.Address o = new org.epos.eposdatamodel.Address();
o.setInstanceId(edmobj.getInstanceId());
o.setMetaId(edmobj.getMetaId());
o.setUid(edmobj.getUid());
o.setStreet(edmobj.getStreet());
o.setCountry(edmobj.getCountry());
o.setPostalCode(edmobj.getPostalCode());
o.setCountryCode(edmobj.getCountrycode());
o.setLocality(edmobj.getLocality());
o = (org.epos.eposdatamodel.Address) VersioningStatusAPI.retrieveVersion(o);
return o;
}
@Override
public List retrieveAll() {
List list = getDbaccess().getAllFromDB(Address.class);
List returnList = new ArrayList<>();
for(Address item : list){
returnList.add(retrieve(item.getInstanceId()));
}
return returnList;
}
@Override
public LinkedEntity retrieveLinkedEntity(String instanceId) {
Address edmobj = (Address) getDbaccess().getOneFromDBByInstanceId(instanceId, Address.class).get(0);
LinkedEntity o = new LinkedEntity();
o.setInstanceId(edmobj.getInstanceId());
o.setMetaId(edmobj.getMetaId());
o.setUid(edmobj.getUid());
o.setEntityType(EntityNames.ADDRESS.name());
return o;
}
}