Search in sources :

Example 6 with ExecutionWindowRestRep

use of com.emc.vipr.model.catalog.ExecutionWindowRestRep in project coprhd-controller by CoprHD.

the class ExecutionWindowsApi method update.

public static void update(String executionWindowId, ExecutionWindowInfo info) {
    ExecutionWindowRestRep window = ExecutionWindowUtils.getExecutionWindow(uri(executionWindowId));
    if (window != null) {
        copyExecutionWindowInfoToExecutionWindow(info, window);
        window.setId(URI.create(executionWindowId));
        createForm(window).validate("executionWindowForm");
        if (validation.hasErrors()) {
            response.status = HttpStatus.SC_BAD_REQUEST;
            ValidationError validationError = null;
            renderApi(getValidationErrors());
        } else {
            ExecutionWindowUpdateParam updateParam = new ExecutionWindowUpdateParam();
            map(updateParam, info);
            ExecutionWindowUtils.updateExecutionWindow(uri(executionWindowId), updateParam);
            info.setId(window.getId().toString());
            renderApi(info);
        }
    } else {
        notFound(Messages.get("ExecutionWindowsApi.windowWithId", executionWindowId));
    }
}
Also used : ExecutionWindowUpdateParam(com.emc.vipr.model.catalog.ExecutionWindowUpdateParam) ExecutionWindowRestRep(com.emc.vipr.model.catalog.ExecutionWindowRestRep) ValidationError(com.emc.vipr.model.catalog.ValidationError)

Example 7 with ExecutionWindowRestRep

use of com.emc.vipr.model.catalog.ExecutionWindowRestRep in project coprhd-controller by CoprHD.

the class ExecutionWindowMapper method map.

public static ExecutionWindowRestRep map(ExecutionWindow from) {
    if (from == null) {
        return null;
    }
    ExecutionWindowRestRep to = new ExecutionWindowRestRep();
    mapDataObjectFields(from, to);
    to.setDayOfMonth(from.getDayOfMonth());
    to.setDayOfWeek(from.getDayOfWeek());
    to.setExecutionWindowLength(from.getExecutionWindowLength());
    to.setExecutionWindowLengthType(from.getExecutionWindowLengthType());
    to.setExecutionWindowType(from.getExecutionWindowType());
    to.setHourOfDayInUTC(from.getHourOfDayInUTC());
    to.setLastDayOfMonth(from.getLastDayOfMonth());
    to.setMinuteOfHourInUTC(from.getMinuteOfHourInUTC());
    to.setTenant(toRelatedResource(ResourceTypeEnum.TENANT, uri(from.getTenant())));
    return to;
}
Also used : ExecutionWindowRestRep(com.emc.vipr.model.catalog.ExecutionWindowRestRep)

Example 8 with ExecutionWindowRestRep

use of com.emc.vipr.model.catalog.ExecutionWindowRestRep in project coprhd-controller by CoprHD.

the class ExecutionWindowUtils method isOverlapping.

public static boolean isOverlapping(ExecutionWindowRestRep newExecutionWindow) {
    DateTimeZone tz = DateTimeZone.UTC;
    List<ExecutionWindowRestRep> executionWindows = ExecutionWindowUtils.getExecutionWindows();
    DateTime startOfWeek = getStartOfWeek(tz);
    DateTime endDateTime = startOfWeek.plusDays(31);
    List<Event> events = asEvents(executionWindows, startOfWeek, endDateTime, tz);
    List<Event> newEvents = asEvents(newExecutionWindow, startOfWeek, endDateTime, tz, 365);
    for (Event event : events) {
        for (Event newEvent : newEvents) {
            if (isOverlapping(event, newEvent)) {
                if (Logger.isDebugEnabled()) {
                    Logger.debug("Overlapping events: " + event + " and " + event);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ExecutionWindowRestRep(com.emc.vipr.model.catalog.ExecutionWindowRestRep) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime)

Example 9 with ExecutionWindowRestRep

use of com.emc.vipr.model.catalog.ExecutionWindowRestRep in project coprhd-controller by CoprHD.

the class ExecutionWindowsApi method create.

public static void create(ExecutionWindowInfo info) {
    ExecutionWindowRestRep window = new ExecutionWindowRestRep();
    copyExecutionWindowInfoToExecutionWindow(info, window);
    createForm(window).validate("executionWindowForm");
    if (validation.hasErrors()) {
        response.status = HttpStatus.SC_BAD_REQUEST;
        renderApi(getValidationErrors());
    } else {
        ExecutionWindowCreateParam createParam = new ExecutionWindowCreateParam();
        map(createParam, info);
        ExecutionWindowUtils.createExecutionWindow(createParam);
        info.setId(window.getId().toString());
        renderApi(info);
    }
}
Also used : ExecutionWindowRestRep(com.emc.vipr.model.catalog.ExecutionWindowRestRep) ExecutionWindowCreateParam(com.emc.vipr.model.catalog.ExecutionWindowCreateParam)

Example 10 with ExecutionWindowRestRep

use of com.emc.vipr.model.catalog.ExecutionWindowRestRep in project coprhd-controller by CoprHD.

the class ExecutionWindowsApi method delete.

public static void delete(String executionWindowId) {
    ExecutionWindowRestRep window = ExecutionWindowUtils.getExecutionWindow(uri(executionWindowId));
    if (window != null) {
        ExecutionWindowUtils.deleteExecutionWindow(window);
        renderApi(executionWindowId);
    } else {
        notFound(Messages.get("ExecutionWindowsApi.windowWithId", executionWindowId));
    }
}
Also used : ExecutionWindowRestRep(com.emc.vipr.model.catalog.ExecutionWindowRestRep)

Aggregations

ExecutionWindowRestRep (com.emc.vipr.model.catalog.ExecutionWindowRestRep)16 Calendar (java.util.Calendar)2 DateTime (org.joda.time.DateTime)2 DateTimeZone (org.joda.time.DateTimeZone)2 Util (play.mvc.Util)2 ViPRCatalogClient2 (com.emc.vipr.client.ViPRCatalogClient2)1 ExecutionWindowCreateParam (com.emc.vipr.model.catalog.ExecutionWindowCreateParam)1 ExecutionWindowUpdateParam (com.emc.vipr.model.catalog.ExecutionWindowUpdateParam)1 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)1 ValidationError (com.emc.vipr.model.catalog.ValidationError)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 Event (util.Event)1