org.finra.herd.service.impl.BusinessObjectDataFinalizeRestoreServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of herd-service Show documentation
Show all versions of herd-service Show documentation
This project contains the business service code. This is a classic service tier where business logic is defined along with it's associated
transaction management configuration.
/*
* Copyright 2015 herd contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.finra.herd.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.finra.herd.dao.StorageUnitDao;
import org.finra.herd.dao.config.DaoSpringModuleConfig;
import org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey;
import org.finra.herd.model.dto.BusinessObjectDataRestoreDto;
import org.finra.herd.model.jpa.NotificationEventTypeEntity;
import org.finra.herd.model.jpa.StorageUnitEntity;
import org.finra.herd.service.BusinessObjectDataFinalizeRestoreHelperService;
import org.finra.herd.service.BusinessObjectDataFinalizeRestoreService;
import org.finra.herd.service.NotificationEventService;
import org.finra.herd.service.helper.StorageUnitHelper;
/**
* An implementation of the business object data finalize restore service.
*/
@Service
@Transactional(value = DaoSpringModuleConfig.HERD_TRANSACTION_MANAGER_BEAN_NAME)
public class BusinessObjectDataFinalizeRestoreServiceImpl implements BusinessObjectDataFinalizeRestoreService
{
@Autowired
private BusinessObjectDataFinalizeRestoreHelperService businessObjectDataFinalizeRestoreHelperService;
/**
* The @Lazy annotation below is added to address the following BeanCreationException: - Error creating bean with name 'notificationEventServiceImpl': Bean
* with name 'notificationEventServiceImpl' has been injected into other beans [...] in its raw version as part of a circular reference, but has eventually
* been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider
* using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
*/
@Autowired
@Lazy
private NotificationEventService notificationEventService;
@Autowired
private StorageUnitDao storageUnitDao;
@Autowired
private StorageUnitHelper storageUnitHelper;
/**
* {@inheritDoc}
*
* This implementation executes non-transactionally, suspends the current transaction if one exists.
*/
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void finalizeRestore(BusinessObjectDataStorageUnitKey storageUnitKey)
{
finalizeRestoreImpl(storageUnitKey);
}
/**
* {@inheritDoc}
*
* This implementation starts a new transaction.
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public List getS3StorageUnitsToRestore(int maxResult)
{
return getS3StorageUnitsToRestoreImpl(maxResult);
}
/**
* Finalizes restore of an S3 storage unit.
*
* @param storageUnitKey the storage unit key
*/
protected void finalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey)
{
// Build the business object data restore DTO.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey);
// Execute the S3 specific steps required to finalize the business object data restore.
businessObjectDataFinalizeRestoreHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Execute the after step regardless if the above step failed or not. Please note that the after step returns true on success and false otherwise.
businessObjectDataFinalizeRestoreHelperService.completeFinalizeRestore(businessObjectDataRestoreDto);
// Create storage unit notification for the origin storage unit.
notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG,
businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(),
businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
}
/**
* Retrieves a list of keys for S3 storage units that are currently being restored.
*
* @param maxResult the maximum number of results to retrieve
*
* @return the list of storage unit keys
*/
protected List getS3StorageUnitsToRestoreImpl(int maxResult)
{
// Retrieves a list of storage units that belong to S3 storage and have the relative S3 storage unit in RESTORING state.
List storageUnitEntities = storageUnitDao.getS3StorageUnitsToRestore(maxResult);
// Build a list of storage unit keys.
List storageUnitKeys = new ArrayList<>();
for (StorageUnitEntity storageUnitEntity : storageUnitEntities)
{
storageUnitKeys.add(storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity));
}
return storageUnitKeys;
}
}