metadataapis.CategorySchemeAPI 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 metadataapis;
import abstractapis.AbstractAPI;
import commonapis.VersioningStatusAPI;
import model.Category;
import model.CategoryScheme;
import org.epos.eposdatamodel.LinkedEntity;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public class CategorySchemeAPI extends AbstractAPI {
public CategorySchemeAPI(String entityName, Class> edmClass) {
super(entityName, edmClass);
}
@Override
public LinkedEntity create(org.epos.eposdatamodel.CategoryScheme 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.CategoryScheme) VersioningStatusAPI.checkVersion(obj);
CategoryScheme edmobj = new CategoryScheme();
edmobj.setVersionId(obj.getVersionId());
edmobj.setInstanceId(obj.getInstanceId());
edmobj.setMetaId(obj.getMetaId());
getDbaccess().updateObject(edmobj);
edmobj.setUid(Optional.ofNullable(obj.getUid()).orElse(getEdmClass().getSimpleName()+"/"+UUID.randomUUID().toString()));
edmobj.setName(Optional.ofNullable(obj.getTitle()).orElse(""));
edmobj.setDescription(Optional.ofNullable(obj.getDescription()).orElse(""));
edmobj.setCode(Optional.ofNullable(obj.getCode()).orElse(""));
edmobj.setColor(Optional.ofNullable(obj.getColor()).orElse(""));
edmobj.setHomepage(Optional.ofNullable(obj.getHomepage()).orElse(""));
edmobj.setOrderitemnumber(Optional.ofNullable(obj.getOrderitemnumber()).orElse(""));
edmobj.setLogo(Optional.ofNullable(obj.getLogo()).orElse(""));
getDbaccess().updateObject(edmobj);
return new LinkedEntity().entityType(entityName)
.instanceId(edmobj.getInstanceId())
.metaId(edmobj.getMetaId())
.uid(edmobj.getUid());
}
@Override
public org.epos.eposdatamodel.CategoryScheme retrieve(String instanceId) {
CategoryScheme edmobj = (CategoryScheme) getDbaccess().getOneFromDBByInstanceId(instanceId, CategoryScheme.class).get(0);
org.epos.eposdatamodel.CategoryScheme o = new org.epos.eposdatamodel.CategoryScheme();
o.setInstanceId(edmobj.getInstanceId());
o.setMetaId(edmobj.getMetaId());
o.setUid(edmobj.getUid());
o.setTitle(edmobj.getName());
o.setDescription(edmobj.getDescription());
o.setCode(edmobj.getCode());
o.setHomepage(edmobj.getHomepage());
o.setLogo(edmobj.getLogo());
o.setColor(edmobj.getColor());
o.setOrderitemnumber(edmobj.getOrderitemnumber());
o = (org.epos.eposdatamodel.CategoryScheme) VersioningStatusAPI.retrieveVersion(o);
return o;
}
@Override
public List retrieveAll() {
List list = getDbaccess().getAllFromDB(CategoryScheme.class);
List returnList = new ArrayList<>();
for(CategoryScheme item : list){
returnList.add(retrieve(item.getInstanceId()));
}
return returnList;
}
@Override
public LinkedEntity retrieveLinkedEntity(String instanceId) {
CategoryScheme edmobj = (CategoryScheme) getDbaccess().getOneFromDBByInstanceId(instanceId, CategoryScheme.class).get(0);
LinkedEntity o = new LinkedEntity();
o.setInstanceId(edmobj.getInstanceId());
o.setMetaId(edmobj.getMetaId());
o.setUid(edmobj.getUid());
o.setEntityType(EntityNames.CATEGORYSCHEME.name());
return o;
}
}