code: static String determineResourceName(final AttachmentResource attachmentResource, final boolean includeExtension) {
  		final String datasourceName = attachmentResource.getDataSource().getName();
  
  		String resourceName;
  
  		if (!valueNullOrEmpty(attachmentResource.getName())) {
  			resourceName = attachmentResource.getName();
  		} else if (!valueNullOrEmpty(datasourceName)) {
  			resourceName = datasourceName;
  		} else {
  			resourceName = "resource" + UUID.randomUUID();
  		}
  		if (includeExtension && !valueNullOrEmpty(datasourceName)) {
  			@SuppressWarnings("UnnecessaryLocalVariable")
  			final String possibleFilename = datasourceName;
  			if (!resourceName.contains(".") && possibleFilename.contains(".")) {
  				final String extension = possibleFilename.substring(possibleFilename.lastIndexOf("."));
  				if (!resourceName.endsWith(extension)) {
  					resourceName += extension;
  				}
  			}
  		} else if (!includeExtension && resourceName.contains(".") && resourceName.equals(datasourceName)) {
  			final String extension = resourceName.substring(resourceName.lastIndexOf("."));
  			resourceName = resourceName.replace(extension, "");
  		}
  		return resourceName;
  	}
docs: Determines the right resource name and optionally attaches the correct extension to the name.