Skip to content

Commit 58ee019

Browse files
More cleanup
1 parent 10ec87f commit 58ee019

File tree

4 files changed

+24
-233
lines changed

4 files changed

+24
-233
lines changed

opencast-backend/annotation-api/src/main/java/org/opencast/annotation/api/ExtendedAnnotationService.java

-49
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,6 @@ Annotation createAnnotation(long trackId, double start, Option<Double> duration,
303303
Scale createScale(long videoId, String name, Option<String> description, Resource resource)
304304
throws ExtendedAnnotationException;
305305

306-
/**
307-
* Creates a copy of a templates scale
308-
*
309-
* @param videoId
310-
* the video id
311-
* @param templateScale
312-
* the template scale to copy
313-
* @param resource
314-
* the resource
315-
* @return the created scale
316-
* @throws ExtendedAnnotationException
317-
* if an error occurs while storing/retrieving from persistence storages
318-
*/
319-
Scale createScaleFromTemplate(long videoId, long templateScale, Resource resource) throws ExtendedAnnotationException;
320-
321306
/**
322307
* Get a scale by id.
323308
*
@@ -444,22 +429,6 @@ ScaleValue createScaleValue(long scaleId, String name, double value, int order,
444429
Questionnaire createQuestionnaire(long videoId, String title, String content,
445430
Option<String> settings, Resource resource) throws ExtendedAnnotationException;
446431

447-
/**
448-
* Creates a questionnaire.
449-
*
450-
* @param templateQuestionnaireId
451-
* the template questionnaire id
452-
* @param videoId
453-
* the video id where the questionnaire is
454-
* @param resource
455-
* the resource
456-
* @return the created questionnaire
457-
* @throws ExtendedAnnotationException
458-
* if an error occurs while storing/retrieving from persistence storage
459-
*/
460-
Option<Questionnaire> createQuestionnaireFromTemplate(long templateQuestionnaireId,
461-
long videoId, Resource resource) throws ExtendedAnnotationException;
462-
463432
/**
464433
* Get a questionnaire value by id.
465434
*
@@ -530,24 +499,6 @@ Category createCategory(Option<String> seriesExtId, Option<Long> seriesCategoryI
530499
Option<Long> scaleId, String name, Option<String> description, Option<String> settings, Resource resource)
531500
throws ExtendedAnnotationException;
532501

533-
/**
534-
* Creates a category
535-
*
536-
* @param seriesExtId
537-
* the external series the category belongs to
538-
* @param seriesCategoryId
539-
* the series category the category belongs to
540-
* @param videoId
541-
* the video id where the category is
542-
* @param resource
543-
* the resource
544-
* @return the created category
545-
* @throws ExtendedAnnotationException
546-
* if an error occurs while storing/retrieving from persistence storage
547-
*/
548-
Option<Category> createCategoryFromTemplate(long templateCategoryId, String seriesExtId, Long seriesCategoryId,
549-
long videoId, Resource resource) throws ExtendedAnnotationException;
550-
551502
/**
552503
* Get a category value by id.
553504
*

opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/endpoint/AbstractExtendedAnnotationsRestService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public Response some(Video v) {
263263

264264
@Override
265265
public Response none() {
266-
Resource resource = eas().createResource(Option.none());
266+
Resource resource = eas().createResource();
267267
final Video v = eas().createVideo(videoExtId,
268268
new ResourceImpl(option(access), resource.getCreatedBy(), resource.getUpdatedBy(), resource.getDeletedBy(), resource.getCreatedAt(), resource.getUpdatedAt(), resource.getDeletedAt(),
269269
resource.getTags()));

opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/endpoint/VideoEndpoint.java

+23-117
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,7 @@ public Response some(Annotation annotation) {
336336
// create a new one
337337
@Override
338338
public Response none() {
339-
Resource resource = eas.createResource(Option.none());
340-
final Annotation a = eas.createAnnotation(
341-
new AnnotationImpl(id, trackId, start, option(duration), content, createdFromQuestionnaire, trimToNone(settings), resource));
342-
return Response.created(annotationLocationUri(videoId, a)).entity(AnnotationDto.toJson.apply(eas, a).toString()).build();
339+
return NOT_FOUND;
343340
}
344341
});
345342
} else {
@@ -430,33 +427,16 @@ public Response apply() {
430427
@POST
431428
@Produces(MediaType.APPLICATION_JSON)
432429
@Path("scales")
433-
public Response postScale(@FormParam("name") final String name, @FormParam("description") final String description,
434-
@FormParam("scale_id") final Long scaleId, @FormParam("access") final Integer access) {
435-
if (scaleId == null) {
436-
return run(array(name), new Function0<>() {
437-
@Override
438-
public Response apply() {
439-
if (eas.getVideo(videoId).isNone()) {
440-
return BAD_REQUEST;
441-
}
442-
443-
Resource resource = eas.createResource(option(access), none());
444-
final Scale scale = eas.createScale(videoId, name, trimToNone(description), resource);
445-
return Response.created(scaleLocationUri(scale)).entity(ScaleDto.toJson.apply(eas, scale).toString()).build();
446-
}
447-
});
448-
}
449-
450-
// TODO Why does this not use `createScale`?
451-
return run(array(scaleId), new Function0<>() {
430+
public Response postScale(@FormParam("name") final String name, @FormParam("description") final String description, @FormParam("access") final Integer access) {
431+
return run(array(name), new Function0<>() {
452432
@Override
453433
public Response apply() {
454-
if (eas.getScale(scaleId, false).isNone() || videoOpt.isNone()) {
434+
if (eas.getVideo(videoId).isNone()) {
455435
return BAD_REQUEST;
456436
}
457437

458438
Resource resource = eas.createResource(option(access), none());
459-
final Scale scale = eas.createScaleFromTemplate(videoId, scaleId, resource);
439+
final Scale scale = eas.createScale(videoId, name, trimToNone(description), resource);
460440
return Response.created(scaleLocationUri(scale)).entity(ScaleDto.toJson.apply(eas, scale).toString()).build();
461441
}
462442
});
@@ -491,10 +471,7 @@ public Response some(Scale scale) {
491471

492472
@Override
493473
public Response none() {
494-
Resource resource = eas.createResource();
495-
final Scale scale = eas.createScale(videoId, name, trimToNone(description), resource);
496-
497-
return Response.created(scaleLocationUri(scale)).entity(ScaleDto.toJson.apply(eas, scale).toString()).build();
474+
return NOT_FOUND;
498475
}
499476
});
500477
}
@@ -626,10 +603,7 @@ public Response some(ScaleValue s) {
626603

627604
@Override
628605
public Response none() {
629-
Resource resource = eas.createResource(option(access), Option.none());
630-
final ScaleValue scaleValue = eas.createScaleValue(scaleId, name, value, order, resource);
631-
632-
return Response.created(scaleValueLocationUri(scaleValue, videoId)).entity(ScaleValueDto.toJson.apply(eas, scaleValue).toString()).build();
606+
return NOT_FOUND;
633607
}
634608
});
635609
}
@@ -712,50 +686,22 @@ public Response none() {
712686
@POST
713687
@Produces(MediaType.APPLICATION_JSON)
714688
@Path("categories")
715-
public Response postCategory(@FormParam("category_id") final Long id,
716-
@FormParam("series_extid") final String seriesExtId,
689+
public Response postCategory(@FormParam("series_extid") final String seriesExtId,
717690
@FormParam("series_category_id") final Long seriesCategoryId, @FormParam("name") final String name,
718691
@FormParam("description") final String description, @FormParam("scale_id") final Long scaleId,
719692
@FormParam("settings") final String settings, @FormParam("access") final Integer access) {
720-
if (id == null) {
721-
return run(array(name), new Function0<>() {
722-
@Override
723-
public Response apply() {
724-
if (eas.getVideo(videoId).isNone()) {
725-
return BAD_REQUEST;
726-
}
727-
728-
Resource resource = eas.createResource(option(access), none());
729-
final Category category = eas.createCategory(trimToNone(seriesExtId), option(seriesCategoryId), videoId,
730-
option(scaleId), name, trimToNone(description), trimToNone(settings), resource);
731-
732-
return Response.created(categoryLocationUri(category)).entity(CategoryDto.toJson.apply(eas, category).toString()).build();
733-
}
734-
});
735-
}
736-
return run(array(id), new Function0<>() {
693+
return run(array(name), new Function0<>() {
737694
@Override
738695
public Response apply() {
739-
if (videoOpt.isNone()) {
696+
if (eas.getVideo(videoId).isNone()) {
740697
return BAD_REQUEST;
741698
}
742699

743-
Resource resource = eas.createResource();
744-
Option<Category> categoryFromTemplate = eas.createCategoryFromTemplate(id, seriesExtId, seriesCategoryId,
745-
videoId, resource);
746-
return categoryFromTemplate.fold(new Option.Match<>() {
747-
748-
@Override
749-
public Response some(Category c) {
750-
return Response.created(categoryLocationUri(c)).entity(CategoryDto.toJson.apply(eas, c).toString()).build();
751-
}
752-
753-
@Override
754-
public Response none() {
755-
return BAD_REQUEST;
756-
}
700+
Resource resource = eas.createResource(option(access), none());
701+
final Category category = eas.createCategory(trimToNone(seriesExtId), option(seriesCategoryId), videoId,
702+
option(scaleId), name, trimToNone(description), trimToNone(settings), resource);
757703

758-
});
704+
return Response.created(categoryLocationUri(category)).entity(CategoryDto.toJson.apply(eas, category).toString()).build();
759705
}
760706
});
761707
}
@@ -820,13 +766,7 @@ name, trimToNone(description), trimToNone(settings),
820766

821767
@Override
822768
public Response none() {
823-
Resource resource = eas.createResource();
824-
final Category category = eas.createCategory(seriesExtIdOpt, seriesCategoryIdOpt, videoId, option(scaleId), name,
825-
trimToNone(description), trimToNone(settings),
826-
new ResourceImpl(option(access), resource.getCreatedBy(), resource.getUpdatedBy(), resource.getDeletedBy(),
827-
resource.getCreatedAt(), resource.getUpdatedAt(), resource.getDeletedAt(), resource.getTags()));
828-
829-
return Response.created(categoryLocationUri(category)).entity(CategoryDto.toJson.apply(eas, category).toString()).build();
769+
return NOT_FOUND;
830770
}
831771
});
832772
}
@@ -961,10 +901,7 @@ public Response some(Label l) {
961901

962902
@Override
963903
public Response none() {
964-
Resource resource = eas.createResource(option(access), Option.none());
965-
final Label label = eas.createLabel(categoryId, value, abbreviation, trimToNone(description), trimToNone(settings), resource);
966-
967-
return Response.created(labelLocationUri(label)).entity(LabelDto.toJson.apply(eas, label).toString()).build();
904+
return NOT_FOUND;
968905
}
969906
});
970907
}
@@ -1115,50 +1052,22 @@ public Response apply() {
11151052
@Produces(MediaType.APPLICATION_JSON)
11161053
@Path("questionnaires")
11171054
public Response postQuestionnaire(
1118-
@FormParam("questionnaireId") final Long id,
11191055
@FormParam("title") final String title,
11201056
@FormParam("content") @DefaultValue("[]") final String content,
11211057
@FormParam("settings") final String settings,
11221058
@FormParam("access") final Integer access) {
1123-
if (id == null) {
1124-
return run(array(title, content), new Function0<>() {
1125-
@Override
1126-
public Response apply() {
1127-
if (eas.getVideo(videoId).isNone()) {
1128-
return BAD_REQUEST;
1129-
}
1130-
1131-
Resource resource = eas.createResource(option(access), none());
1132-
final Questionnaire questionnaire = eas.createQuestionnaire(videoId, title, content, trimToNone(settings),
1133-
resource);
1134-
1135-
return Response.created(questionnaireLocationUri(questionnaire)).entity(QuestionnaireDto.toJson.apply(eas, questionnaire).toString()).build();
1136-
}
1137-
});
1138-
}
1139-
1140-
return run(array(id), new Function0<>() {
1059+
return run(array(title, content), new Function0<>() {
11411060
@Override
11421061
public Response apply() {
1143-
if (videoOpt.isNone()) {
1062+
if (eas.getVideo(videoId).isNone()) {
11441063
return BAD_REQUEST;
11451064
}
11461065

1147-
Resource resource = eas.createResource();
1148-
Option<Questionnaire> questionnaireFromTemplate = eas.createQuestionnaireFromTemplate(id, videoId, resource);
1149-
1150-
return questionnaireFromTemplate.fold(new Option.Match<>() {
1151-
@Override
1152-
public Response some(Questionnaire q) {
1153-
return Response.created(questionnaireLocationUri(q))
1154-
.entity(QuestionnaireDto.toJson.apply(eas, q).toString()).build();
1155-
}
1066+
Resource resource = eas.createResource(option(access), none());
1067+
final Questionnaire questionnaire = eas.createQuestionnaire(videoId, title, content, trimToNone(settings),
1068+
resource);
11561069

1157-
@Override
1158-
public Response none() {
1159-
return BAD_REQUEST;
1160-
}
1161-
});
1070+
return Response.created(questionnaireLocationUri(questionnaire)).entity(QuestionnaireDto.toJson.apply(eas, questionnaire).toString()).build();
11621071
}
11631072
});
11641073
}
@@ -1250,10 +1159,7 @@ public Response some(Comment c) {
12501159

12511160
@Override
12521161
public Response none() {
1253-
Resource resource = eas.createResource();
1254-
final Comment comment = eas.createComment(annotationId, Option.none(), text, resource);
1255-
1256-
return Response.created(commentLocationUri(comment, videoId, trackId)).entity(CommentDto.toJson.apply(eas, comment).toString()).build();
1162+
return NOT_FOUND;
12571163
}
12581164
});
12591165
}

opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/impl/persistence/ExtendedAnnotationServiceJpaImpl.java

-66
Original file line numberDiff line numberDiff line change
@@ -382,23 +382,6 @@ public Scale createScale(long videoId, String name, Option<String> description,
382382
}
383383
}
384384

385-
@Override
386-
public Scale createScaleFromTemplate(long videoId, long templateScaleId, Resource resource)
387-
throws ExtendedAnnotationException {
388-
// Copy scale
389-
Option<Scale> templateScale = getScale(templateScaleId, false);
390-
if (templateScale.isNone())
391-
throw new ExtendedAnnotationException(Cause.SERVER_ERROR);
392-
393-
Scale scale = createScale(videoId, templateScale.get().getName(),
394-
templateScale.get().getDescription(), resource);
395-
396-
for (ScaleValue sv : getScaleValuesByScaleId(templateScaleId)) {
397-
createScaleValue(scale.getId(), sv.getName(), sv.getValue(), sv.getOrder(), resource);
398-
}
399-
return scale;
400-
}
401-
402385
@Override
403386
public Option<Scale> getScale(long id, boolean includeDeleted) throws ExtendedAnnotationException {
404387
final Option<Scale> scale;
@@ -503,40 +486,6 @@ public Category createCategory(Option<String> seriesExtId, Option<Long> seriesCa
503486
}
504487
}
505488

506-
@Override
507-
public Option<Category> createCategoryFromTemplate(final long templateCategoryId, final String seriesExtId,
508-
final Long seriesCategoryId, final long videoId, final Resource resource) throws ExtendedAnnotationException {
509-
return getCategory(templateCategoryId, false).map(new Function<>() {
510-
@Override
511-
public Category apply(Category c) {
512-
Long scaleId = null;
513-
// Copy scale
514-
if (c.getScaleId().isSome()) {
515-
Option<Scale> scale = getScale(c.getScaleId().get(), false);
516-
if (scale.isNone())
517-
throw new ExtendedAnnotationException(Cause.SERVER_ERROR);
518-
519-
scaleId = createScale(videoId, scale.get().getName(), scale.get().getDescription(), resource)
520-
.getId();
521-
522-
for (ScaleValue sv : getScaleValuesByScaleId(c.getScaleId().get())) {
523-
createScaleValue(scaleId, sv.getName(), sv.getValue(), sv.getOrder(), resource);
524-
}
525-
}
526-
// Copy category
527-
final CategoryDto copyDto = CategoryDto.create(option(seriesExtId), option(seriesCategoryId),
528-
videoId, option(scaleId), c.getName(), c.getDescription(), c.getSettings(), resource);
529-
Category category = tx(namedQuery.persist(copyDto)).toCategory();
530-
531-
// Copy labels
532-
getLabelsByCategoryId(templateCategoryId).forEach(
533-
l -> createLabel(category.getId(), l.getValue(), l.getAbbreviation(), l.getDescription(),
534-
l.getSettings(), resource));
535-
return category;
536-
}
537-
});
538-
}
539-
540489
@Override
541490
public void updateCategory(final Category c) throws ExtendedAnnotationException {
542491
update(CategoryDto.class, "Category.findByIdIncludeDeleted", c.getId(), new Effect<>() {
@@ -900,21 +849,6 @@ public Stream<Questionnaire> getQuestionnaires(final long videoId)
900849
.filter(this::hasResourceAccess);
901850
}
902851

903-
@Override
904-
public Option<Questionnaire> createQuestionnaireFromTemplate(
905-
final long templateQuestionnaireId,
906-
final long videoId,
907-
final Resource resource) throws ExtendedAnnotationException {
908-
return getQuestionnaire(templateQuestionnaireId, false).map(new Function<>() {
909-
@Override
910-
public Questionnaire apply(Questionnaire q) {
911-
final QuestionnaireDto copyDto = QuestionnaireDto.create(videoId, q.getTitle(), q.getContent(), q.getSettings(), resource);
912-
913-
return tx(namedQuery.persist(copyDto)).toQuestionnaire();
914-
}
915-
});
916-
}
917-
918852
@Override
919853
public void updateQuestionnaire(final Questionnaire q) throws ExtendedAnnotationException {
920854
update(QuestionnaireDto.class, "Questionnaire.findByIdIncludeDeleted", q.getId(), new Effect<>() {

0 commit comments

Comments
 (0)