class TargetTypesServiceImpl implements TargetTypesService {

	@Override
	public String updateTargetTypeDetails(CreateUpdateTargetTypeDetailsRequest targetTypesDetails, final String userId) throws PacManException {
		targetTypesDetails.setName(targetTypesDetails.getName().toLowerCase().trim().replaceAll(" ", "-"));
		boolean isTargetTypeExits = targetTypesRepository.existsById(targetTypesDetails.getName());
		if (isTargetTypeExits) {
			Date currentDate = new Date();
			TargetTypes existingTargetType = targetTypesRepository.findById(targetTypesDetails.getName().trim()).get();
			existingTargetType.setTargetDesc(targetTypesDetails.getDesc());
			existingTargetType.setCategory(targetTypesDetails.getCategory());
			existingTargetType.setDataSourceName(targetTypesDetails.getDataSource());
			existingTargetType.setTargetConfig(targetTypesDetails.getConfig());
			existingTargetType.setUserId(userId);
			String endpoint = config.getElasticSearch().getDevIngestHost() + ":" + config.getElasticSearch().getDevIngestPort() + "/" + targetTypesDetails.getDataSource() + "_"+ targetTypesDetails.getName() + "/" + targetTypesDetails.getName();
			existingTargetType.setEndpoint(endpoint);
			existingTargetType.setModifiedDate(currentDate);
			existingTargetType.setDomain(targetTypesDetails.getDomain());
			targetTypesRepository.save(existingTargetType);
			return AdminConstants.TARGET_TYPE_UPDATION_SUCCESS;
		} else {
			throw new PacManException(AdminConstants.TARGET_TYPE_NAME_NOT_EXITS);
		}
	}

}