Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Nov 29, 2024
1 parent 4260001 commit 4e12265
Show file tree
Hide file tree
Showing 18 changed files with 416 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Represents content compounds units to validation secrets application converter;
*/
public class ContentCompoundUnitToValidationSecretsApplicationConverter {
public class ContentCompoundUnitsToValidationSecretsApplicationConverter {

/**
* Converts given content compound units to validation secrets application.
Expand All @@ -25,7 +25,7 @@ public static ValidationSecretsApplication convert(List<ContentCompoundUnitDto>
element -> validationSecretsUnits.add(
ValidationSecretsUnit.of(
element.getProvider(),
element.getCredentialsFieldsFull())));
element.getCredentials())));

return ValidationSecretsApplication.of(validationSecretsUnits);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.objectstorage.converter;

import com.objectstorage.dto.ContentCompoundUnitDto;
import com.objectstorage.dto.RepositoryContentApplicationUnitDto;
import com.objectstorage.model.ValidationSecretsApplication;
import com.objectstorage.model.ValidationSecretsUnit;

import java.util.ArrayList;
import java.util.List;

/**
* Represents repository content application units to validation secrets application converter;
*/
public class RepositoryContentApplicationUnitsToValidationSecretsApplicationConverter {

/**
* Converts given content compound units to validation secrets application.
*
* @param repositoryContentApplicationUnits given repository content application units.
* @return converted validation secrets application.
*/
public static ValidationSecretsApplication convert(
List<RepositoryContentApplicationUnitDto> repositoryContentApplicationUnits) {
List<ValidationSecretsUnit> validationSecretsUnits = new ArrayList<>();

repositoryContentApplicationUnits.forEach(
element -> validationSecretsUnits.add(
ValidationSecretsUnit.of(
element.getProvider(),
element.getCredentials())));

return ValidationSecretsApplication.of(validationSecretsUnits);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public class ContentCompoundUnitDto {
/**
* Represents full credentials fields.
*/
private CredentialsFieldsFull credentialsFieldsFull;
private CredentialsFieldsFull credentials;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.objectstorage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.InputStream;

/**
* Represents folder content unit.
*/
@Getter
@AllArgsConstructor(staticName = "of")
public class FolderContentUnitDto {
/**
* Represents folder entity name.
*/
private String location;

/**
* Represents folder entity content.
*/
private byte[] content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.objectstorage.dto;

import com.objectstorage.model.CredentialsFieldsFull;
import com.objectstorage.model.Provider;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Represents repository content application unit.
*/
@Getter
@AllArgsConstructor(staticName = "of")
public class RepositoryContentApplicationUnitDto {
/**
* Represents root location for internal file system.
*/
private String root;

/**
* Represents provider.
*/
private Provider provider;

/**
* Represents full credentials fields.
*/
private CredentialsFieldsFull credentials;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class PropertiesEntity {
@ConfigProperty(name = "workspace.content.backup.directory")
String workspaceContentBackupDirectory;

@ConfigProperty(name = "workspace.content.backup.unit")
String workspaceContentBackupUnit;

@ConfigProperty(name = "workspace.compression.file.name")
String workspaceCompressionFileName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,55 @@ public ContentEntity findByProviderAndSecret(Integer provider, Integer secret) t
return ContentEntity.of(id, provider, secret, root);
}

/**
* Retrieves all the persisted content entities.
*
* @return retrieved content entities.
* @throws RepositoryOperationFailureException if repository operation fails.
*/
public List<ContentEntity> findAll() throws RepositoryOperationFailureException {
ResultSet resultSet;

try {
resultSet =
repositoryExecutor.performQueryWithResult(
String.format(
"SELECT t.id, t.root, t.provider, t.secret FROM %s as t",
properties.getDatabaseContentTableName()));

} catch (QueryExecutionFailureException | QueryEmptyResultException e) {
throw new RepositoryOperationFailureException(e.getMessage());
}

List<ContentEntity> result = new ArrayList<>();

Integer id;
String root;
Integer provider;
Integer secret;

try {
while (resultSet.next()) {
id = resultSet.getInt("id");
root = resultSet.getString("root");
provider = resultSet.getInt("provider");
secret = resultSet.getInt("secret");

result.add(ContentEntity.of(id, provider, secret, root));
}
} catch (SQLException e) {
throw new RepositoryOperationFailureException(e.getMessage());
}

try {
resultSet.close();
} catch (SQLException e) {
throw new RepositoryOperationFailureException(e.getMessage());
}

return result;
}

/**
* Deletes all entities with the given provider and secret from content table.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.objectstorage.repository.facade;

import com.objectstorage.dto.ContentCompoundUnitDto;
import com.objectstorage.dto.RepositoryContentUnitDto;
import com.objectstorage.dto.EarliestTemporateContentDto;
import com.objectstorage.dto.TemporateContentUnitDto;
import com.objectstorage.dto.*;
import com.objectstorage.entity.repository.ContentEntity;
import com.objectstorage.entity.repository.ProviderEntity;
import com.objectstorage.entity.repository.SecretEntity;
Expand Down Expand Up @@ -160,7 +157,7 @@ public EarliestTemporateContentDto retrieveEarliestTemporateContent() throws Tem
throw new TemporateContentRetrievalFailureException(e.getMessage());
}

CredentialsFieldsFull secrets =
CredentialsFieldsFull credentials =
repositoryConfigurationHelper.convertRawSecretsToContentCredentials(
provider,
secret.getSession(),
Expand All @@ -179,7 +176,7 @@ public EarliestTemporateContentDto retrieveEarliestTemporateContent() throws Tem
RepositoryContentUnitDto.of(
contentEntity.getRoot()),
provider,
secrets));
credentials));
}

return EarliestTemporateContentDto.of(
Expand Down Expand Up @@ -300,6 +297,58 @@ public RepositoryContentUnitDto retrieveContentApplication(ValidationSecretsUnit
return RepositoryContentUnitDto.of(contentEntity.getRoot());
}

/**
* Retrieves all content applications from the content repository.
*
* @return retrieved all content applications.
* @throws ContentApplicationRetrievalFailureException if content applications retrieval fails.
*/
public List<RepositoryContentApplicationUnitDto> retrieveAllContentApplications()
throws ContentApplicationRetrievalFailureException {
List<ContentEntity> contentEntities;

try {
contentEntities = contentRepository.findAll();
} catch (RepositoryOperationFailureException e) {
throw new ContentApplicationRetrievalFailureException(e.getMessage());
}

List<RepositoryContentApplicationUnitDto> repositoryContentApplicationUnits = new ArrayList<>();

for (ContentEntity content : contentEntities) {
ProviderEntity rawProvider;

try {
rawProvider = providerRepository.findById(content.getProvider());
} catch (RepositoryOperationFailureException e) {
throw new ContentApplicationRetrievalFailureException(e.getMessage());
}

Provider provider =
repositoryConfigurationHelper.convertRawProviderToContentProvider(rawProvider.getName());

SecretEntity secret;

try {
secret = secretRepository.findById(content.getSecret());
} catch (RepositoryOperationFailureException e) {
throw new ContentApplicationRetrievalFailureException(e.getMessage());
}

CredentialsFieldsFull credentials =
repositoryConfigurationHelper.convertRawSecretsToContentCredentials(
provider,
secret.getSession(),
secret.getCredentials());

repositoryContentApplicationUnits.add(
RepositoryContentApplicationUnitDto.of(
content.getRoot(), provider, credentials));
}

return repositoryContentApplicationUnits;
}

/**
* Removes temporate content from the temporate repository with the given hash.
*
Expand Down
Loading

0 comments on commit 4e12265

Please sign in to comment.