AttachmentUtil { public static CPAttachmentFileEntry upsertCPAttachmentFileEntry( CPAttachmentFileEntryService cpAttachmentFileEntryService, UniqueFileNameProvider uniqueFileNameProvider, AttachmentBase64 attachmentBase64, long classNameId, long classPK, int type, ServiceContext serviceContext) throws Exception { _validateMethodRequiredParams( attachmentBase64.getId(), attachmentBase64.getExternalReferenceCode()); Calendar displayCalendar = CalendarFactoryUtil.getCalendar( serviceContext.getTimeZone()); if (attachmentBase64.getDisplayDate() != null) { displayCalendar = DateConfigUtil.convertDateToCalendar( attachmentBase64.getDisplayDate()); } DateConfig displayDateConfig = new DateConfig(displayCalendar); Calendar expirationCalendar = CalendarFactoryUtil.getCalendar( serviceContext.getTimeZone()); expirationCalendar.add(Calendar.MONTH, 1); if (attachmentBase64.getExpirationDate() != null) { expirationCalendar = DateConfigUtil.convertDateToCalendar( attachmentBase64.getExpirationDate()); } DateConfig expirationDateConfig = new DateConfig(expirationCalendar); long fileEntryId = 0; FileEntry fileEntry = addFileEntry( attachmentBase64.getAttachment(), serviceContext.getScopeGroupId(), serviceContext.getUserId(), uniqueFileNameProvider); if (fileEntry != null) { fileEntryId = fileEntry.getFileEntryId(); } return cpAttachmentFileEntryService.upsertCPAttachmentFileEntry( serviceContext.getScopeGroupId(), classNameId, classPK, GetterUtil.getLong(attachmentBase64.getId()), fileEntryId, displayDateConfig.getMonth(), displayDateConfig.getDay(), displayDateConfig.getYear(), displayDateConfig.getHour(), displayDateConfig.getMinute(), expirationDateConfig.getMonth(), expirationDateConfig.getDay(), expirationDateConfig.getYear(), expirationDateConfig.getHour(), expirationDateConfig.getMinute(), GetterUtil.get(attachmentBase64.getNeverExpire(), false), getTitleMap(null, attachmentBase64.getTitle()), GetterUtil.getString(attachmentBase64.getOptions()), GetterUtil.getDouble(attachmentBase64.getPriority()), type, attachmentBase64.getExternalReferenceCode(), serviceContext); }  static FileEntry addFileEntry(
			Attachment attachment, long groupId, long userId,
			UniqueFileNameProvider uniqueFileNameProvider); static FileEntry addFileEntry(
			AttachmentUrl attachmentUrl, long groupId, long userId,
			UniqueFileNameProvider uniqueFileNameProvider); static FileEntry addFileEntry(
			String base64EncodedContent, long groupId, long userId,
			UniqueFileNameProvider uniqueFileNameProvider); static Map<Locale, String> getTitleMap(
			CPAttachmentFileEntry cpAttachmentFileEntry,
			Map<String, String> titleMap); static CPAttachmentFileEntry upsertCPAttachmentFileEntry(
			CPAttachmentFileEntryService cpAttachmentFileEntryService,
			UniqueFileNameProvider uniqueFileNameProvider,
			AttachmentBase64 attachmentBase64, long classNameId, long classPK,
			int type, ServiceContext serviceContext); static CPAttachmentFileEntry upsertCPAttachmentFileEntry(
			CPAttachmentFileEntryService cpAttachmentFileEntryService,
			UniqueFileNameProvider uniqueFileNameProvider,
			AttachmentUrl attachmentUrl, long classNameId, long classPK,
			int type, ServiceContext serviceContext); static CPAttachmentFileEntry upsertCPAttachmentFileEntry(
			long groupId,
			CPAttachmentFileEntryService cpAttachmentFileEntryService,
			UniqueFileNameProvider uniqueFileNameProvider,
			Attachment attachment, long classNameId, long classPK, int type,
			ServiceContext serviceContext);  }
@Test(expected = MethodRequiredParameterMissingException.class) public void testUpsertCPAttachmentFileEntryWithInvalidAttachment() throws Exception { AttachmentUtil.upsertCPAttachmentFileEntry( 0, null, null, new Attachment(), 0, 0, 0, new ServiceContext()); }
@Test(expected = MethodRequiredParameterMissingException.class) public void testUpsertCPAttachmentFileEntryWithInvalidAttachmentBase64() throws Exception { AttachmentUtil.upsertCPAttachmentFileEntry( null, null, new AttachmentBase64(), 0, 0, 0, new ServiceContext()); }
@Test(expected = MethodRequiredParameterMissingException.class) public void testUpsertCPAttachmentFileEntryWithInvalidAttachmentUrl() throws Exception { AttachmentUtil.upsertCPAttachmentFileEntry( null, null, new AttachmentUrl(), 0, 0, 0, new ServiceContext()); }