001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.oozie.executor.jpa;
020
021import org.apache.oozie.WorkflowJobBean;
022import org.apache.oozie.client.WorkflowJob;
023import org.apache.oozie.util.DateUtils;
024
025import java.sql.Timestamp;
026import java.util.ArrayList;
027import java.util.Date;
028import java.util.List;
029
030public class WorkflowJobsBasicInfoFromParentId {
031    protected final String parentId;
032    protected final int limit;
033    protected final int offset;
034
035    WorkflowJobsBasicInfoFromParentId(final String parentId, final int offset, final int limit) {
036        this.parentId = parentId;
037        this.offset = offset;
038        this.limit = limit;
039    }
040
041    List<WorkflowJobBean> getBeanFromArray(final List resultList) {
042        final List<WorkflowJobBean> wfActionBeanList = new ArrayList<>();
043
044        for (final Object element : resultList) {
045            final WorkflowJobBean wfBean = new WorkflowJobBean();
046            final Object[] arr = (Object[])element;
047
048            final String id = (String) arr[0];
049            if (id != null) {
050                wfBean.setId(id);
051            }
052
053            final String status = (String) arr[1];
054            if (status != null) {
055                wfBean.setStatus(WorkflowJob.Status.valueOf(status));
056            }
057
058            final Timestamp endTime = (Timestamp) arr[2];
059            if (endTime != null) {
060                wfBean.setEndTime(DateUtils.toDate(endTime));
061            }
062
063            final Timestamp lastModifiedTime = (Timestamp) arr[3];
064            if (lastModifiedTime != null) {
065                final Date d = DateUtils.toDate(lastModifiedTime);
066                wfBean.setLastModifiedTime(d);
067            }
068            wfActionBeanList.add(wfBean);
069        }
070
071        return wfActionBeanList;
072    }
073}