Search in sources :

Example 1 with Templates

use of org.ovirt.engine.api.model.Templates in project ovirt-engine by oVirt.

the class BackendTemplatesResource method mapCollection.

protected Templates mapCollection(List<VmTemplate> entities) {
    Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
    boolean includeData = details.contains(DetailHelper.MAIN);
    boolean includeSize = details.contains("size");
    if (includeData) {
        // Fill VmInit for entities - the search query no join the VmInit to Templates
        IdsQueryParameters params = new IdsQueryParameters();
        List<Guid> ids = entities.stream().map(VmTemplate::getId).collect(Collectors.toList());
        params.setId(ids);
        QueryReturnValue queryReturnValue = runQuery(QueryType.GetVmsInit, params);
        if (queryReturnValue.getSucceeded() && queryReturnValue.getReturnValue() != null) {
            List<VmInit> vmInits = queryReturnValue.getReturnValue();
            Map<Guid, VmInit> initMap = Entities.businessEntitiesById(vmInits);
            for (VmTemplate template : entities) {
                template.setVmInit(initMap.get(template.getId()));
            }
        }
    }
    Templates collection = new Templates();
    if (includeData) {
        for (VmTemplate entity : entities) {
            Template template = map(entity);
            collection.getTemplates().add(addLinks(populate(template, entity)));
            DisplayHelper.adjustDisplayData(this, template);
        }
    }
    if (includeSize) {
        collection.setSize((long) entities.size());
    }
    return collection;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) IdsQueryParameters(org.ovirt.engine.core.common.queries.IdsQueryParameters) Templates(org.ovirt.engine.api.model.Templates) Guid(org.ovirt.engine.core.compat.Guid) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 2 with Templates

use of org.ovirt.engine.api.model.Templates in project ovirt-engine by oVirt.

the class BackendStorageDomainTemplatesResource method list.

@Override
public Templates list() {
    Templates templates = new Templates();
    boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED_CONSTRAINT_PARAMETER, true, false);
    if (unregistered) {
        List<org.ovirt.engine.core.common.businessentities.VmTemplate> unregisteredTemplates = getBackendCollection(QueryType.GetUnregisteredVmTemplates, new IdQueryParameters(storageDomainId));
        List<Template> collection = new ArrayList<>();
        for (org.ovirt.engine.core.common.businessentities.VmTemplate entity : unregisteredTemplates) {
            Template vmTemplate = map(entity);
            collection.add(addLinks(populate(vmTemplate, entity)));
        }
        templates.getTemplates().addAll(collection);
    } else {
        templates.getTemplates().addAll(getCollection());
    }
    return templates;
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) Templates(org.ovirt.engine.api.model.Templates) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 3 with Templates

use of org.ovirt.engine.api.model.Templates in project ovirt-engine by oVirt.

the class V3TemplatesInAdapter method adapt.

@Override
public Templates adapt(V3Templates from) {
    Templates to = new Templates();
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetActive()) {
        to.setActive(from.getActive());
    }
    if (from.isSetSize()) {
        to.setSize(from.getSize());
    }
    if (from.isSetTotal()) {
        to.setTotal(from.getTotal());
    }
    to.getTemplates().addAll(adaptIn(from.getTemplates()));
    return to;
}
Also used : Templates(org.ovirt.engine.api.model.Templates) V3Templates(org.ovirt.engine.api.v3.types.V3Templates)

Aggregations

Templates (org.ovirt.engine.api.model.Templates)3 Template (org.ovirt.engine.api.model.Template)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 ArrayList (java.util.ArrayList)1 V3Templates (org.ovirt.engine.api.v3.types.V3Templates)1 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 Guid (org.ovirt.engine.core.compat.Guid)1