use of org.opencastproject.scheduler.api.SchedulerTransactionLockException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method updateEvent.
@Override
public void updateEvent(String eventId, Opt<Date> startDateTime, Opt<Date> endDateTime, Opt<String> captureAgentId, Opt<Set<String>> userIds, Opt<MediaPackage> mediaPackage, Opt<Map<String, String>> wfProperties, Opt<Map<String, String>> caMetadata, Opt<Opt<Boolean>> optOut, String origin) throws NotFoundException, UnauthorizedException, SchedulerTransactionLockException, SchedulerConflictException, SchedulerException {
logger.debug("Start updating event {}.", eventId);
HttpPut put = new HttpPut("/" + eventId);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
if (startDateTime.isSome())
params.add(new BasicNameValuePair("start", Long.toString(startDateTime.get().getTime())));
if (endDateTime.isSome())
params.add(new BasicNameValuePair("end", Long.toString(endDateTime.get().getTime())));
if (captureAgentId.isSome())
params.add(new BasicNameValuePair("agent", captureAgentId.get()));
if (userIds.isSome())
params.add(new BasicNameValuePair("users", StringUtils.join(userIds.get(), ",")));
if (mediaPackage.isSome())
params.add(new BasicNameValuePair("mediaPackage", MediaPackageParser.getAsXml(mediaPackage.get())));
if (wfProperties.isSome())
params.add(new BasicNameValuePair("wfproperties", toPropertyString(wfProperties.get())));
if (caMetadata.isSome())
params.add(new BasicNameValuePair("agentparameters", toPropertyString(caMetadata.get())));
if (optOut.isSome()) {
params.add(new BasicNameValuePair("updateOptOut", Boolean.toString(true)));
if (optOut.get().isSome())
params.add(new BasicNameValuePair("optOut", Boolean.toString(optOut.get().get())));
} else {
params.add(new BasicNameValuePair("updateOptOut", Boolean.toString(false)));
}
params.add(new BasicNameValuePair("origin", origin));
put.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(put, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED, SC_FORBIDDEN, SC_CONFLICT);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Event {} was not found by the scheduler service", eventId);
throw new NotFoundException("Event '" + eventId + "' not found on remote scheduler service!");
} else if (SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Event {} successfully updated with capture agent metadata.", eventId);
return;
} else if (response != null && SC_CONFLICT == response.getStatusLine().getStatusCode()) {
String errorJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(errorJson);
JSONObject error = (JSONObject) json.get("error");
String errorCode = (String) error.get("code");
if (SchedulerTransactionLockException.ERROR_CODE.equals(errorCode)) {
logger.info("Event is locked by a transaction, unable to update event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to update event " + eventId);
} else if (SchedulerConflictException.ERROR_CODE.equals(errorCode)) {
logger.info("Conflicting events found when updating event {}", eventId);
throw new SchedulerConflictException("Conflicting events found when updating event " + eventId);
} else {
throw new SchedulerException("Unexpected error code " + errorCode);
}
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to update the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to update the event " + eventId);
} else if (SC_FORBIDDEN == response.getStatusLine().getStatusCode()) {
logger.info("Forbidden to update the event {}.", eventId);
throw new SchedulerException("Event with specified ID cannot be updated");
} else {
throw new SchedulerException("Unexpected status code " + response.getStatusLine());
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to update event " + eventId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to update event " + eventId);
}
use of org.opencastproject.scheduler.api.SchedulerTransactionLockException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method addEvent.
@Override
public void addEvent(Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Map<String, String> wfProperties, Map<String, String> caMetadata, Opt<Boolean> optOut, Opt<String> schedulingSource, String origin) throws UnauthorizedException, SchedulerTransactionLockException, SchedulerConflictException, SchedulerException {
HttpPost post = new HttpPost("/");
String eventId = mediaPackage.getIdentifier().compact();
logger.debug("Start adding a new event {} through remote Schedule Service", eventId);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("start", Long.toString(startDateTime.getTime())));
params.add(new BasicNameValuePair("end", Long.toString(endDateTime.getTime())));
params.add(new BasicNameValuePair("agent", captureAgentId));
params.add(new BasicNameValuePair("users", StringUtils.join(userIds, ",")));
params.add(new BasicNameValuePair("mediaPackage", MediaPackageParser.getAsXml(mediaPackage)));
params.add(new BasicNameValuePair("wfproperties", toPropertyString(wfProperties)));
params.add(new BasicNameValuePair("agentparameters", toPropertyString(caMetadata)));
if (optOut.isSome())
params.add(new BasicNameValuePair("optOut", Boolean.toString(optOut.get())));
if (schedulingSource.isSome())
params.add(new BasicNameValuePair("source", schedulingSource.get()));
params.add(new BasicNameValuePair("origin", origin));
post.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(post, SC_CREATED, SC_UNAUTHORIZED, SC_CONFLICT);
try {
if (response != null && SC_CREATED == response.getStatusLine().getStatusCode()) {
logger.info("Successfully added event {} to the scheduler service", eventId);
return;
} else if (response != null && SC_CONFLICT == response.getStatusLine().getStatusCode()) {
String errorJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(errorJson);
JSONObject error = (JSONObject) json.get("error");
String errorCode = (String) error.get("code");
if (SchedulerTransactionLockException.ERROR_CODE.equals(errorCode)) {
logger.info("Event is locked by a transaction, unable to add event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to add event " + eventId);
} else if (SchedulerConflictException.ERROR_CODE.equals(errorCode)) {
logger.info("Conflicting events found when adding event {}", eventId);
throw new SchedulerConflictException("Conflicting events found when adding event " + eventId);
} else {
throw new SchedulerException("Unexpected error code " + errorCode);
}
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to create the event");
throw new UnauthorizedException("Unauthorized to create the event");
} else {
throw new SchedulerException("Unable to add event " + eventId + " to the scheduler service");
}
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to add event " + eventId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
}
use of org.opencastproject.scheduler.api.SchedulerTransactionLockException in project opencast by opencast.
the class SchedulerServiceImpl method addEventInternal.
private void addEventInternal(Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Map<String, String> wfProperties, Map<String, String> caMetadata, String modificationOrigin, Opt<Boolean> optOutStatus, Opt<String> schedulingSource, Opt<String> trxId) throws SchedulerException {
notNull(startDateTime, "startDateTime");
notNull(endDateTime, "endDateTime");
notEmpty(captureAgentId, "captureAgentId");
notNull(userIds, "userIds");
notNull(mediaPackage, "mediaPackage");
notNull(wfProperties, "wfProperties");
notNull(caMetadata, "caMetadata");
notEmpty(modificationOrigin, "modificationOrigin");
notNull(optOutStatus, "optOutStatus");
notNull(schedulingSource, "schedulingSource");
notNull(trxId, "trxId");
if (endDateTime.before(startDateTime))
throw new IllegalArgumentException("The end date is before the start date");
final String mediaPackageId = mediaPackage.getIdentifier().compact();
try {
AQueryBuilder query = assetManager.createQuery();
// TODO this query runs twice if called from SchedulerTransactionImpl#addEvent
AResult result = query.select(query.nothing()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId).and(query.version().isLatest()))).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isSome()) {
logger.warn("Mediapackage with id '{}' already exists!", mediaPackageId);
throw new SchedulerConflictException("Mediapackage with id '" + mediaPackageId + "' already exists!");
}
Opt<String> seriesId = Opt.nul(StringUtils.trimToNull(mediaPackage.getSeries()));
// Get opt out status
boolean optOut = getOptOutStatus(seriesId, optOutStatus);
if (trxId.isNone()) {
// Check for locked transactions
if (schedulingSource.isSome() && persistence.hasTransaction(schedulingSource.get())) {
logger.warn("Unable to add event '{}', source '{}' is currently locked due to an active transaction!", mediaPackageId, schedulingSource.get());
throw new SchedulerTransactionLockException("Unable to add event, locked source " + schedulingSource.get());
}
// Check for conflicting events if not opted out
if (!optOut) {
List<MediaPackage> conflictingEvents = findConflictingEvents(captureAgentId, startDateTime, endDateTime);
if (conflictingEvents.size() > 0) {
logger.info("Unable to add event {}, conflicting events found: {}", mediaPackageId, conflictingEvents);
throw new SchedulerConflictException("Unable to add event, conflicting events found for event " + mediaPackageId);
}
}
}
// Load dublincore and acl for update
Opt<DublinCoreCatalog> dublinCore = DublinCoreUtil.loadEpisodeDublinCore(workspace, mediaPackage);
Option<AccessControlList> acl = authorizationService.getAcl(mediaPackage, AclScope.Episode);
// Get updated agent properties
Map<String, String> finalCaProperties = getFinalAgentProperties(caMetadata, wfProperties, captureAgentId, seriesId, dublinCore);
// Persist asset
String checksum = calculateChecksum(workspace, getEventCatalogUIAdapterFlavors(), startDateTime, endDateTime, captureAgentId, userIds, mediaPackage, dublinCore, wfProperties, finalCaProperties, optOut, acl.toOpt().getOr(new AccessControlList()));
persistEvent(mediaPackageId, modificationOrigin, checksum, Opt.some(startDateTime), Opt.some(endDateTime), Opt.some(captureAgentId), Opt.some(userIds), Opt.some(mediaPackage), Opt.some(wfProperties), Opt.some(finalCaProperties), Opt.some(optOut), schedulingSource, trxId);
if (trxId.isNone()) {
// Send updates
sendUpdateAddEvent(mediaPackageId, acl.toOpt(), dublinCore, Opt.some(startDateTime), Opt.some(endDateTime), Opt.some(userIds), Opt.some(captureAgentId), Opt.some(finalCaProperties), Opt.some(optOut));
// Update last modified
touchLastEntry(captureAgentId);
}
} catch (SchedulerException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to create event with id '{}': {}", mediaPackageId, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.scheduler.api.SchedulerTransactionLockException in project opencast by opencast.
the class SchedulerServiceImpl method updateEventInternal.
private void updateEventInternal(final String mpId, String modificationOrigin, Opt<Date> startDateTime, Opt<Date> endDateTime, Opt<String> captureAgentId, Opt<Set<String>> userIds, Opt<MediaPackage> mediaPackage, Opt<Map<String, String>> wfProperties, Opt<Map<String, String>> caMetadata, Opt<Opt<Boolean>> optOutOption, Opt<String> trxId) throws NotFoundException, SchedulerException {
notEmpty(mpId, "mpId");
notEmpty(modificationOrigin, "modificationOrigin");
notNull(startDateTime, "startDateTime");
notNull(endDateTime, "endDateTime");
notNull(captureAgentId, "captureAgentId");
notNull(userIds, "userIds");
notNull(mediaPackage, "mediaPackage");
notNull(wfProperties, "wfProperties");
notNull(caMetadata, "caMetadata");
notNull(optOutOption, "optOutStatus");
notNull(trxId, "trxId");
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
ASelectQuery select = query.select(query.snapshot(), p.start().target(), p.end().target(), query.propertiesOf(WORKFLOW_NAMESPACE, CA_NAMESPACE), p.agent().target(), p.source().target(), p.checksum().target(), p.optOut().target(), p.presenters().target()).where(withOrganization(query).and(query.mediaPackageId(mpId).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace()))));
Opt<ARecord> optEvent = select.run().getRecords().head();
if (optEvent.isNone())
throw new NotFoundException("No event found while updating event " + mpId);
ARecord record = optEvent.get();
if (record.getSnapshot().isNone())
throw new NotFoundException("No mediapackage found while updating event " + mpId);
Opt<DublinCoreCatalog> dublinCoreOpt = loadEpisodeDublinCoreFromAsset(record.getSnapshot().get());
if (dublinCoreOpt.isNone())
throw new NotFoundException("No dublincore found while updating event " + mpId);
verifyActive(mpId, record);
Date start = record.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
Date end = record.getProperties().apply(Properties.getDate(END_DATE_CONFIG));
if ((startDateTime.isSome() || endDateTime.isSome()) && endDateTime.getOr(end).before(startDateTime.getOr(start)))
throw new SchedulerException("The end date is before the start date");
String agentId = record.getProperties().apply(Properties.getString(AGENT_CONFIG));
Opt<String> seriesId = Opt.nul(record.getSnapshot().get().getMediaPackage().getSeries());
boolean oldOptOut = record.getProperties().apply(Properties.getBoolean(OPTOUT_CONFIG));
// Get opt out status
Opt<Boolean> optOut = Opt.none();
for (Opt<Boolean> optOutToUpdate : optOutOption) {
optOut = Opt.some(getOptOutStatus(seriesId, optOutToUpdate));
}
if (trxId.isNone()) {
// Check for locked transactions
Opt<String> source = record.getProperties().apply(Properties.getStringOpt(SOURCE_CONFIG));
if (source.isSome() && persistence.hasTransaction(source.get())) {
logger.warn("Unable to update event '{}', source '{}' is currently locked due to an active transaction!", mpId, source.get());
throw new SchedulerTransactionLockException("Unable to update event, locked source " + source.get());
}
// Set to opted out
boolean isNewOptOut = optOut.isSome() && optOut.get();
// Changed to ready for recording
boolean readyForRecording = optOut.isSome() && !optOut.get();
// Has a conflict related property be changed?
boolean propertyChanged = captureAgentId.isSome() || startDateTime.isSome() || endDateTime.isSome();
// Check for conflicting events
if (!isNewOptOut && (readyForRecording || (propertyChanged && !oldOptOut))) {
List<MediaPackage> conflictingEvents = $(findConflictingEvents(captureAgentId.getOr(agentId), startDateTime.getOr(start), endDateTime.getOr(end))).filter(new Fn<MediaPackage, Boolean>() {
@Override
public Boolean apply(MediaPackage mp) {
return !mpId.equals(mp.getIdentifier().compact());
}
}).toList();
if (conflictingEvents.size() > 0) {
logger.info("Unable to update event {}, conflicting events found: {}", mpId, conflictingEvents);
throw new SchedulerConflictException("Unable to update event, conflicting events found for event " + mpId);
}
}
}
Set<String> presenters = getPresenters(record.getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
Map<String, String> wfProps = record.getProperties().filter(filterByNamespace._2(WORKFLOW_NAMESPACE)).group(toKey, toValue);
Map<String, String> caProperties = record.getProperties().filter(filterByNamespace._2(CA_NAMESPACE)).group(toKey, toValue);
boolean propertiesChanged = false;
boolean dublinCoreChanged = false;
// Get workflow properties
for (Map<String, String> wfPropsToUpdate : wfProperties) {
propertiesChanged = true;
wfProps = wfPropsToUpdate;
}
// Get capture agent properties
for (Map<String, String> caMetadataToUpdate : caMetadata) {
propertiesChanged = true;
caProperties = caMetadataToUpdate;
}
if (captureAgentId.isSome())
propertiesChanged = true;
Opt<AccessControlList> acl = Opt.none();
Opt<DublinCoreCatalog> dublinCore = Opt.none();
Opt<AccessControlList> aclOld = loadEpisodeAclFromAsset(record.getSnapshot().get());
for (MediaPackage mpToUpdate : mediaPackage) {
// Check for series change
if (ne(record.getSnapshot().get().getMediaPackage().getSeries(), mpToUpdate.getSeries())) {
propertiesChanged = true;
seriesId = Opt.nul(mpToUpdate.getSeries());
}
// Check for ACL change and send update
Option<AccessControlList> aclNew = authorizationService.getAcl(mpToUpdate, AclScope.Episode);
if (aclNew.isSome()) {
if (aclOld.isNone() || !AccessControlUtil.equals(aclNew.get(), aclOld.get())) {
acl = aclNew.toOpt();
}
}
// Check for dublin core change and send update
Opt<DublinCoreCatalog> dublinCoreNew = DublinCoreUtil.loadEpisodeDublinCore(workspace, mpToUpdate);
if (dublinCoreNew.isSome() && !DublinCoreUtil.equals(dublinCoreOpt.get(), dublinCoreNew.get())) {
dublinCoreChanged = true;
propertiesChanged = true;
dublinCore = dublinCoreNew;
}
}
Opt<Map<String, String>> finalCaProperties = Opt.none();
if (propertiesChanged) {
finalCaProperties = Opt.some(getFinalAgentProperties(caProperties, wfProps, captureAgentId.getOr(agentId), seriesId, some(dublinCore.getOr(dublinCoreOpt.get()))));
}
String checksum = calculateChecksum(workspace, getEventCatalogUIAdapterFlavors(), startDateTime.getOr(start), endDateTime.getOr(end), captureAgentId.getOr(agentId), userIds.getOr(presenters), mediaPackage.getOr(record.getSnapshot().get().getMediaPackage()), some(dublinCore.getOr(dublinCoreOpt.get())), wfProperties.getOr(wfProps), finalCaProperties.getOr(caProperties), optOut.getOr(oldOptOut), acl.getOr(aclOld.getOr(new AccessControlList())));
if (trxId.isNone()) {
String oldChecksum = record.getProperties().apply(Properties.getString(CHECKSUM));
if (checksum.equals(oldChecksum)) {
logger.debug("Updated event {} has same checksum, ignore update", mpId);
return;
}
}
// Update asset
persistEvent(mpId, modificationOrigin, checksum, startDateTime, endDateTime, captureAgentId, userIds, mediaPackage, wfProperties, finalCaProperties, optOut, Opt.<String>none(), trxId);
if (trxId.isNone()) {
// Send updates
sendUpdateAddEvent(mpId, acl, dublinCore, startDateTime, endDateTime, userIds, Opt.some(agentId), finalCaProperties, optOut);
// Update last modified
if (propertiesChanged || dublinCoreChanged || optOutOption.isSome() || startDateTime.isSome() || endDateTime.isSome()) {
touchLastEntry(agentId);
for (String agent : captureAgentId) {
touchLastEntry(agent);
}
}
}
} catch (NotFoundException e) {
throw e;
} catch (SchedulerException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to update event with id '{}': {}", mpId, getStackTrace(e));
throw new SchedulerException(e);
}
}
use of org.opencastproject.scheduler.api.SchedulerTransactionLockException in project opencast by opencast.
the class SchedulerRestService method updateEvent.
@PUT
@Path("{id}")
@RestQuery(name = "updaterecordings", description = "Updates specified event", returnDescription = "Status OK is returned if event was successfully updated, NOT FOUND if specified event does not exist or BAD REQUEST if data is missing or invalid", pathParameters = { @RestParameter(name = "id", description = "ID of event to be updated", isRequired = true, type = Type.STRING) }, restParameters = { @RestParameter(name = "start", isRequired = false, description = "Updated start date for event", type = Type.INTEGER), @RestParameter(name = "end", isRequired = false, description = "Updated end date for event", type = Type.INTEGER), @RestParameter(name = "agent", isRequired = false, description = "Updated agent for event", type = Type.STRING), @RestParameter(name = "users", isRequired = false, type = Type.STRING, description = "Updated comma separated list of user ids (speakers/lecturers) for the event"), @RestParameter(name = "mediaPackage", isRequired = false, description = "Updated media package for event", type = Type.TEXT), @RestParameter(name = "wfproperties", isRequired = false, description = "Workflow configuration properties", type = Type.TEXT), @RestParameter(name = "agentparameters", isRequired = false, description = "Updated Capture Agent properties", type = Type.TEXT), @RestParameter(name = "updateOptOut", isRequired = true, defaultValue = "false", description = "Whether to update the opt out status", type = Type.BOOLEAN), @RestParameter(name = "optOut", isRequired = false, description = "Update opt out status", type = Type.BOOLEAN), @RestParameter(name = "origin", isRequired = false, description = "The origin", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Event was successfully updated"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_CONFLICT, description = "Unable to update event, conflicting events found (ConflicsFound)"), @RestResponse(responseCode = HttpServletResponse.SC_CONFLICT, description = "Unable to update event, event locked by a transaction (TransactionLock)"), @RestResponse(responseCode = HttpServletResponse.SC_FORBIDDEN, description = "Event with specified ID cannot be updated"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to update the event. Maybe you need to authenticate."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Data is missing or invalid") })
public Response updateEvent(@PathParam("id") String eventID, @FormParam("start") Long startTime, @FormParam("end") Long endTime, @FormParam("agent") String agentId, @FormParam("users") String users, @FormParam("mediaPackage") String mediaPackageXml, @FormParam("wfproperties") String workflowProperties, @FormParam("agentparameters") String agentParameters, @FormParam("updateOptOut") boolean updateOptOut, @FormParam("optOut") Boolean optOutBoolean, @FormParam("origin") String origin) throws UnauthorizedException {
if (StringUtils.isBlank(origin))
origin = SchedulerService.ORIGIN;
if (startTime != null) {
if (startTime < 0) {
logger.debug("Cannot add event with negative start time ({} < 0)", startTime);
return RestUtil.R.badRequest("Cannot add event with negative start time");
}
if (endTime != null && endTime <= startTime) {
logger.debug("Cannot add event without proper end time ({} <= {})", startTime, endTime);
return RestUtil.R.badRequest("Cannot add event without proper end time");
}
}
MediaPackage mediaPackage = null;
if (StringUtils.isNotBlank(mediaPackageXml)) {
try {
mediaPackage = MediaPackageParser.getFromXml(mediaPackageXml);
} catch (Exception e) {
logger.debug("Could not parse media packagey", e);
return Response.status(Status.BAD_REQUEST).build();
}
}
Map<String, String> caProperties = null;
if (StringUtils.isNotBlank(agentParameters)) {
try {
Properties prop = parseProperties(agentParameters);
caProperties = new HashMap<>();
caProperties.putAll((Map) prop);
} catch (Exception e) {
logger.debug("Could not parse capture agent properties: {}", agentParameters, e);
return Response.status(Status.BAD_REQUEST).build();
}
}
Map<String, String> wfProperties = null;
if (StringUtils.isNotBlank(workflowProperties)) {
try {
Properties prop = parseProperties(workflowProperties);
wfProperties = new HashMap<>();
wfProperties.putAll((Map) prop);
} catch (IOException e) {
logger.debug("Could not parse workflow configuration properties: {}", workflowProperties, e);
return Response.status(Status.BAD_REQUEST).build();
}
}
Set<String> userIds = null;
String[] ids = StringUtils.split(StringUtils.trimToNull(users), ",");
if (ids != null) {
userIds = new HashSet<>(Arrays.asList(ids));
}
Date startDate = null;
if (startTime != null) {
startDate = new DateTime(startTime).toDateTime(DateTimeZone.UTC).toDate();
}
Date endDate = null;
if (endTime != null) {
endDate = new DateTime(endTime).toDateTime(DateTimeZone.UTC).toDate();
}
final Opt<Opt<Boolean>> optOut;
if (updateOptOut) {
optOut = Opt.some(Opt.nul(optOutBoolean));
} else {
optOut = Opt.none();
}
try {
service.updateEvent(eventID, Opt.nul(startDate), Opt.nul(endDate), Opt.nul(StringUtils.trimToNull(agentId)), Opt.nul(userIds), Opt.nul(mediaPackage), Opt.nul(wfProperties), Opt.nul(caProperties), optOut, origin);
return Response.ok().build();
} catch (SchedulerTransactionLockException | SchedulerConflictException e) {
return Response.status(Status.CONFLICT).entity(generateErrorResponse(e)).type(MediaType.APPLICATION_JSON).build();
} catch (SchedulerException e) {
logger.warn("Error updating event with id '{}'", eventID, e);
return Response.status(Status.FORBIDDEN).build();
} catch (NotFoundException e) {
logger.info("Event with id '{}' does not exist.", eventID);
return Response.status(Status.NOT_FOUND).build();
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
logger.error("Unable to update event with id '{}'", eventID, e);
return Response.serverError().build();
}
}
Aggregations