private void updateCollection( final SessionIdentifier sessionIdentifier, final GalleryCollectionIdentifier galleryCollectionIdentifier, final GalleryGroupIdentifier galleryGroupIdentifier, final String name, final String prioString, final String sharedString) throws GalleryServiceException, LoginRequiredException, PermissionDeniedException, ValidationException { Long prio; Boolean shared; final List<ValidationError> errors = new ArrayList<ValidationError>(); { try { if (prioString == null || prioString.length() == 0) { prio = null; } else { prio = parseUtil.parseLong(prioString); } } catch (final ParseException e) { prio = null; errors.add(new ValidationErrorSimple("illegal prio")); } } { try { shared = parseUtil.parseBoolean(sharedString); } catch (final ParseException e) { shared = null; errors.add(new ValidationErrorSimple("illegal shared")); } } if (!errors.isEmpty()) { throw new ValidationException(new ValidationResultImpl(errors)); } else { galleryService.updateCollection( sessionIdentifier, galleryCollectionIdentifier, galleryGroupIdentifier, name, prio, shared); } }
@Override protected Widget createGalleryContentWidget(final HttpServletRequest request) throws IOException, PermissionDeniedException, RedirectException, LoginRequiredException { try { final ListWidget widgets = new ListWidget(); widgets.add(new H1Widget(getTitle())); final String id = request.getParameter(GalleryGuiConstants.PARAMETER_COLLECTION_ID); final String name = request.getParameter(GalleryGuiConstants.PARAMETER_COLLECTION_NAME); final String referer = request.getParameter(GalleryGuiConstants.PARAMETER_REFERER); final String prio = request.getParameter(GalleryGuiConstants.PARAMETER_COLLECTION_PRIO); final String shared = request.getParameter(GalleryGuiConstants.PARAMETER_COLLECTION_SHARED); final String groupId = request.getParameter(GalleryGuiConstants.PARAMETER_GROUP_ID); final SessionIdentifier sessionIdentifier = authenticationService.createSessionIdentifier(request); final GalleryCollectionIdentifier galleryCollectionIdentifier = galleryService.createCollectionIdentifier(id); final GalleryCollection galleryCollection = galleryService.getCollection(sessionIdentifier, galleryCollectionIdentifier); if (name != null && prio != null && groupId != null && shared != null) { try { final GalleryGroupIdentifier galleryGroupIdentifier = galleryService.createGroupIdentifier(groupId); updateCollection( sessionIdentifier, galleryCollectionIdentifier, galleryGroupIdentifier, name, prio, shared); if (referer != null && referer.length() > 0) { throw new RedirectException(referer); } else { throw new RedirectException( galleryGuiLinkFactory.entryListUrl(request, galleryCollectionIdentifier)); } } catch (final ValidationException e) { widgets.add("create collection => failed"); widgets.add(new ValidationExceptionWidget(e)); } } final FormWidget formWidget = new FormWidget(); formWidget.addFormInputWidget( new FormInputHiddenWidget(GalleryGuiConstants.PARAMETER_REFERER) .addDefaultValue(buildRefererUrl(request))); formWidget.addFormInputWidget( new FormInputHiddenWidget(GalleryGuiConstants.PARAMETER_COLLECTION_ID) .addValue(galleryCollection.getId())); formWidget.addFormInputWidget( new FormInputHiddenWidget(GalleryGuiConstants.PARAMETER_GROUP_ID) .addValue(galleryCollection.getGroupId())); formWidget.addFormInputWidget( new FormInputTextWidget(GalleryGuiConstants.PARAMETER_COLLECTION_NAME) .addLabel("Name...") .addDefaultValue(galleryCollection.getName())); formWidget.addFormInputWidget( new FormInputTextWidget(GalleryGuiConstants.PARAMETER_COLLECTION_PRIO) .addLabel("Prio...") .addDefaultValue(galleryCollection.getPriority())); formWidget.addFormInputWidget( new FormInputTextWidget(GalleryGuiConstants.PARAMETER_COLLECTION_SHARED) .addLabel("Shared") .addPlaceholder("shared...") .addDefaultValue(galleryCollection.getShared())); formWidget.addFormInputWidget(new FormInputSubmitWidget("update")); widgets.add(formWidget); return widgets; } catch (final GalleryServiceException e) { logger.debug(e.getClass().getName(), e); return new ExceptionWidget(e); } catch (final AuthenticationServiceException e) { logger.debug(e.getClass().getName(), e); return new ExceptionWidget(e); } }