Search in sources :

Example 1 with VmIcon

use of org.ovirt.engine.core.common.businessentities.VmIcon in project ovirt-engine by oVirt.

the class GetVmIconsQuery method executeQueryCommand.

/**
 * query returned type: {@code Map<Guid, String>} requested icon id -> icon data
 */
@Override
protected void executeQueryCommand() {
    Map<Guid, String> result = new HashMap<>();
    for (Guid iconId : getParameters().getIconIds()) {
        final VmIcon vmIcon = vmIconDao.get(iconId);
        result.put(iconId, vmIcon.getDataUrl());
    }
    setReturnValue(result);
}
Also used : VmIcon(org.ovirt.engine.core.common.businessentities.VmIcon) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with VmIcon

use of org.ovirt.engine.core.common.businessentities.VmIcon in project ovirt-engine by oVirt.

the class VmIconDaoTest method testRemoveIfUnusedWithUsed.

@Test
public void testRemoveIfUnusedWithUsed() {
    prepareDao().removeIfUnused(FixturesTool.SMALL_ICON_ID);
    final VmIcon survivor = prepareDao().get(FixturesTool.SMALL_ICON_ID);
    assertEquals(FixturesTool.SMALL_ICON_ID, survivor.getId());
}
Also used : VmIcon(org.ovirt.engine.core.common.businessentities.VmIcon) Test(org.junit.Test)

Example 3 with VmIcon

use of org.ovirt.engine.core.common.businessentities.VmIcon in project ovirt-engine by oVirt.

the class VmIconMapper method map.

@Mapping(from = VmIcon.class, to = Icon.class)
public static Icon map(VmIcon entity, Icon template) {
    final Icon model = template != null ? template : new Icon();
    model.setId(entity.getId().toString());
    final Pair<String, String> typeAndData = entity.getTypeAndData();
    model.setMediaType(typeAndData.getFirst());
    model.setData(typeAndData.getSecond());
    return model;
}
Also used : VmIcon(org.ovirt.engine.core.common.businessentities.VmIcon) Icon(org.ovirt.engine.api.model.Icon)

Example 4 with VmIcon

use of org.ovirt.engine.core.common.businessentities.VmIcon in project ovirt-engine by oVirt.

the class BackendIconsResourceTest method setUpVmIcons.

public static List<VmIcon> setUpVmIcons() {
    final List<VmIcon> result = new ArrayList<>();
    // iterating over NAMES, because it is shorter than GUIDS and it is used in verifyCollection() method
    for (int i = 0; i < NAMES.length; i++) {
        final VmIcon vmIcon = new VmIcon(GUIDS[i], DATA_URLS[i]);
        result.add(vmIcon);
    }
    return result;
}
Also used : VmIcon(org.ovirt.engine.core.common.businessentities.VmIcon) ArrayList(java.util.ArrayList)

Example 5 with VmIcon

use of org.ovirt.engine.core.common.businessentities.VmIcon in project ovirt-engine by oVirt.

the class VmIconDaoImpl method ensureIconInDatabase.

@Override
public Guid ensureIconInDatabase(final String icon) {
    if (icon == null) {
        throw new IllegalArgumentException("Argument 'icon' should not be null");
    }
    return TransactionSupport.executeInNewTransaction(() -> {
        final List<VmIcon> existingIcons = getByDataUrl(icon);
        if (!existingIcons.isEmpty()) {
            return existingIcons.get(0).getId();
        }
        final VmIcon newIcon = new VmIcon(Guid.newGuid(), icon);
        save(newIcon);
        return newIcon.getId();
    });
}
Also used : VmIcon(org.ovirt.engine.core.common.businessentities.VmIcon)

Aggregations

VmIcon (org.ovirt.engine.core.common.businessentities.VmIcon)8 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Icon (org.ovirt.engine.api.model.Icon)1 Guid (org.ovirt.engine.core.compat.Guid)1