package org.sagebionetworks.repo.web.service.metadata;

import org.sagebionetworks.repo.manager.EntityManager;
import org.sagebionetworks.repo.model.DatastoreException;
import org.sagebionetworks.repo.model.FileEntity;
import org.sagebionetworks.repo.model.InvalidModelException;
import org.sagebionetworks.repo.model.UnauthorizedException;
import org.sagebionetworks.repo.model.UserInfo;
import org.sagebionetworks.repo.web.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;

public class FileEntityMetadataProvider implements EntityValidator<FileEntity>, TypeSpecificUpdateProvider<FileEntity> {
	@Autowired
	EntityManager manager;

	@Override
	public void validateEntity(FileEntity entity, EntityEvent event)
			throws InvalidModelException, NotFoundException,
			DatastoreException, UnauthorizedException {
		if(EventType.CREATE == event.getType() || EventType.UPDATE == event.getType() || EventType.NEW_VERSION == event.getType()){
			// This is for PLFM-1754.
			if(entity.getDataFileHandleId() == null) {
				throw new IllegalArgumentException("FileEntity.dataFileHandleId cannot be null");
			}
		}
		if (EventType.CREATE == event.getType() && entity.getFileNameOverride() != null) {
			throw new IllegalArgumentException("fileNameOverride field is deprecated and should not be set.");
		}
	}

	@Override
	public void entityUpdated(UserInfo userInfo, FileEntity entity) {
		if (entity.getFileNameOverride() != null) {
			FileEntity original = (FileEntity) manager.getEntity(userInfo, entity.getId());
			if (original.getFileNameOverride() != entity.getFileNameOverride()) {
				throw new IllegalArgumentException("fileNameOverride field is deprecated and should not be set.");
			}
		}
	}
}

@@ -634,16 +634,148 @@
 ity%3E %7B%0D%0A
+%09private static final String FILE_NAME_OVERRIDE_DEPRECATED_REASON = %22fileNameOverride field is deprecated and should not be set.%22;%0D%0A
 %09@Autowi
@@ -1416,69 +1416,44 @@
 ion(
-%22fileNameOverride field is deprecated and should not be set.%22
+FILE_NAME_OVERRIDE_DEPRECATED_REASON
 );%0D%0A
@@ -1791,69 +1791,44 @@
 ion(
-%22fileNameOverride field is deprecated and should not be set.%22
+FILE_NAME_OVERRIDE_DEPRECATED_REASON
 );%0D%0A

extract constant