use of alfio.model.TicketCategory.TicketAccessType in project alf.io by alfio-event.
the class EventManager method updateEventHeader.
public void updateEventHeader(Event original, EventModification em, String username) {
IntPredicate ownershipChecker = checkOwnershipByOrgId(username, organizationRepository);
boolean sameOrganization = original.getOrganizationId() == em.getOrganizationId();
Validate.isTrue(ownershipChecker.test(original.getOrganizationId()) && (sameOrganization || ownershipChecker.test(em.getOrganizationId())), "Invalid organizationId");
int eventId = original.getId();
Validate.isTrue(sameOrganization || groupRepository.countByEventId(eventId) == 0, "Cannot change organization because there is a group linked to this event.");
Validate.isTrue(sameOrganization || !subscriptionRepository.hasLinkedSubscription(eventId), "Cannot change organization because there are one or more subscriptions linked.");
boolean formatUpdated = em.getFormat() != original.getFormat();
if (em.getFormat() == EventFormat.ONLINE && formatUpdated) {
Validate.isTrue(original.getAllowedPaymentProxies().stream().allMatch(p -> p != PaymentProxy.ON_SITE), ERROR_ONLINE_ON_SITE_NOT_COMPATIBLE);
}
String timeZone = ObjectUtils.firstNonNull(em.getZoneId(), em.getGeolocation() != null ? em.getGeolocation().getTimeZone() : null);
String latitude = ObjectUtils.firstNonNull(em.getLatitude(), em.getGeolocation() != null ? em.getGeolocation().getLatitude() : null);
String longitude = ObjectUtils.firstNonNull(em.getLongitude(), em.getGeolocation() != null ? em.getGeolocation().getLongitude() : null);
final ZoneId zoneId = ZoneId.of(timeZone);
final ZonedDateTime begin = em.getBegin().toZonedDateTime(zoneId);
final ZonedDateTime end = em.getEnd().toZonedDateTime(zoneId);
eventRepository.updateHeader(eventId, em.getDisplayName(), em.getWebsiteUrl(), em.getExternalUrl(), em.getTermsAndConditionsUrl(), em.getPrivacyPolicyUrl(), em.getImageUrl(), em.getFileBlobId(), em.getLocation(), latitude, longitude, begin, end, timeZone, em.getOrganizationId(), em.getLocales(), em.getFormat());
createOrUpdateEventDescription(eventId, em);
if (!original.getBegin().equals(begin) || !original.getEnd().equals(end)) {
fixOutOfRangeCategories(em, username, zoneId, end);
}
if (formatUpdated) {
// update ticket access type for categories if the format has been updated
var ticketAccessType = evaluateTicketAccessType(original.getFormat(), em.getFormat());
ticketCategoryRepository.updateTicketAccessTypeForEvent(eventId, ticketAccessType);
}
extensionManager.handleEventHeaderUpdate(eventRepository.findById(eventId), organizationRepository.findOrganizationForUser(username, em.getOrganizationId()).orElseThrow());
}
Aggregations