package com.onaro.sanscreen.client.view.reservations.functions; import com.onaro.client.leekui.runtime.OnaroAdapterUtils; import com.onaro.client.swing.table.functional.IFunction; import com.onaro.sanscreen.client.view.common.functions.AbstractContextAwareBulkFunction; import com.onaro.sanscreen.client.view.refresh.RefreshUtils; import com.onaro.sanscreen.server.interfaces.ServerInterfacesUtils; import com.onaro.sanscreen.server.interfaces.data.Context; import com.onaro.sanscreen.server.interfaces.data.ServerInterfaceException; import com.onaro.sanscreen.server.interfaces.data.inventory.Port; import com.onaro.sanscreen.server.interfaces.data.reservation.ReservationEligibility; import com.onaro.sanscreen.server.interfaces.remote.ReservationRemote; import org.eclipse.core.runtime.IAdaptable; import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.Map; import java.util.Set; /** * This class is used to populate the preferred column data for port micro view. */ public class GetPortPreferenceBulkFunction extends AbstractContextAwareBulkFunction { //we need selected hosts in the request to figure out the preference value for the port object. private Set selectedHosts; public GetPortPreferenceBulkFunction(Set selectedHosts) { this.selectedHosts = selectedHosts; } public interface IGetPortPreferenceBulkFunction extends IFunction { } @Override protected void evaluate(Collection inputs, Context context, Map outputMap) throws InterruptedException, InvocationTargetException { Map portEligibility; try { //As all the ports belong to the same storage because of the single selection for storage, // just picking up the first port to get the storage id. I firstObject = inputs.iterator().next(); Long storageId = -1L; if (firstObject != null) { Port port = OnaroAdapterUtils.getAdapter(firstObject, Port.class); storageId = port.getDeviceId(); } ReservationRemote remote = ServerInterfacesUtils.getReservationRemote(); portEligibility = remote.getPortEligibilityForPathReservation(selectedHosts, storageId); } catch (ServerInterfaceException e) { throw new InvocationTargetException(e); } OnaroAdapterUtils.getAdaptableToValueMap(inputs, Long.class, portEligibility, outputMap); } @Override protected RefreshUtils.MethodDescriptor getMethodCalled() { return new RefreshUtils.MethodDescriptor(ReservationRemote.class, "getPortEligibilityForPathReservation", Set.class, Long.class); //$NON-NLS-1$ } }