blob: a8ab0cefa7497e57a9a9c32737847a2664e191aa [file] [log] [blame]
/*-
* ============LICENSE_START=======================================================
* OSAM
* ================================================================================
* Copyright (C) 2018 AT&T
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.osam.job.impl;
import org.onap.osam.job.dao.job.JobStatus;
import org.onap.osam.job.dao.job.OsamJob;
import org.onap.osam.job.IJobFactory;
import org.onap.osam.job.JobType;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.UUID;
@Component
public class JobFactory implements IJobFactory {
@Override
public OsamJob createRootJob(JobType jobType, AsyncJobRequest request, String userId, Integer indexInBulk, Map<String, Object> jobData){
OsamJob job = new OsamJob();
job.setStatus(JobStatus.PENDING);
job.setUuid(UUID.randomUUID());
job.setUserId(userId);
job.setTypeAndData(jobType, jobData);
job.setSharedData(new JobSharedData(job.getUuid(), userId, request));
job.setIndexInBulk(indexInBulk);
return job;
}
@Override
public OsamJob createChildJob(JobType jobType, JobStatus jobStatus, AsyncJobRequest request, JobSharedData parentSharedData, Map<String, Object> jobData) {
OsamJob job = new OsamJob();
job.setStatus(jobStatus);
job.setUuid(UUID.randomUUID());
job.setUserId(parentSharedData.getUserId());
job.setTypeAndData(jobType, jobData);
job.setSharedData(new JobSharedData(job.getUuid(), request, parentSharedData));
return job;
}
}