All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.dsf.fhir.authorization.LocationAuthorizationRule Maven / Gradle / Ivy

package dev.dsf.fhir.authorization;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.hl7.fhir.r4.model.Location;

import dev.dsf.common.auth.conf.Identity;
import dev.dsf.fhir.authentication.OrganizationProvider;
import dev.dsf.fhir.authorization.read.ReadAccessHelper;
import dev.dsf.fhir.dao.LocationDao;
import dev.dsf.fhir.dao.provider.DaoProvider;
import dev.dsf.fhir.help.ParameterConverter;
import dev.dsf.fhir.service.ReferenceResolver;

public class LocationAuthorizationRule extends AbstractMetaTagAuthorizationRule
{
	public LocationAuthorizationRule(DaoProvider daoProvider, String serverBase, ReferenceResolver referenceResolver,
			OrganizationProvider organizationProvider, ReadAccessHelper readAccessHelper,
			ParameterConverter parameterConverter)
	{
		super(Location.class, daoProvider, serverBase, referenceResolver, organizationProvider, readAccessHelper,
				parameterConverter);
	}

	@Override
	protected Optional newResourceOkForCreate(Connection connection, Identity identity, Location newResource)
	{
		return newResourceOk(connection, newResource);
	}

	@Override
	protected Optional newResourceOkForUpdate(Connection connection, Identity identity, Location newResource)
	{
		return newResourceOk(connection, newResource);
	}

	private Optional newResourceOk(Connection connection, Location newResource)
	{
		List errors = new ArrayList<>();

		if (!hasValidReadAccessTag(connection, newResource))
		{
			errors.add("Location is missing valid read access tag");
		}

		if (errors.isEmpty())
			return Optional.empty();
		else
			return Optional.of(errors.stream().collect(Collectors.joining(", ")));
	}

	@Override
	protected boolean resourceExists(Connection connection, Location newResource)
	{
		// no unique criteria for Location
		return false;
	}

	@Override
	protected boolean modificationsOk(Connection connection, Location oldResource, Location newResource)
	{
		// no unique criteria for Location
		return true;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy