Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecl 1058 #58

Merged
merged 3 commits into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void removeAssignment(String providerId, String dataSetId,
dataSet.setProviderId(providerId);
dataSet.setId(dataSetId);
//
findNewRepresentationVersionsWithLatestRevisions(dataSet,deletedRevisions,representation);
findNewRepresentationVersionsWithLatestRevisions(dataSet, deletedRevisions, representation);
}

private void findNewRepresentationVersionsWithLatestRevisions(DataSet dataSet, Set<Revision> deletedRevisions, Representation representation) {
Expand All @@ -229,7 +229,7 @@ private void findNewRepresentationVersionsWithLatestRevisions(DataSet dataSet, S
}
}

private void findNewRepresentationVersionWithLatestRevision(Representation unassignedRepresentation, Revision revision, DataSet dataset){
private void findNewRepresentationVersionWithLatestRevision(Representation unassignedRepresentation, Revision revision, DataSet dataset) {

List<Representation> representations = recordDAO.getAllRepresentationVersionsForRevisionName(
unassignedRepresentation.getCloudId(),
Expand All @@ -254,13 +254,13 @@ private boolean isRepresentationBeingRemoved(Representation foundRepresentation,
return false;
}

private boolean isRepresentationInsideDataSet(Representation rep, DataSet dataSet){
private boolean isRepresentationInsideDataSet(Representation rep, DataSet dataSet) {
try {
Collection<CompoundDataSetId> datasetIds = dataSetDAO.getDataSetAssignmentsByRepresentationVersion(rep.getCloudId(),rep.getRepresentationName(),rep.getVersion());
Collection<CompoundDataSetId> datasetIds = dataSetDAO.getDataSetAssignmentsByRepresentationVersion(rep.getCloudId(), rep.getRepresentationName(), rep.getVersion());
CompoundDataSetId compoundDataSetId = new CompoundDataSetId(dataSet.getProviderId(), dataSet.getId());
if(datasetIds.contains(compoundDataSetId)){
if (datasetIds.contains(compoundDataSetId)) {
return true;
}else{
} else {
return false;
}
} catch (RepresentationNotExistsException e) {
Expand All @@ -269,7 +269,7 @@ private boolean isRepresentationInsideDataSet(Representation rep, DataSet dataSe
return false;
}

private void insertRevisionAsLatestForRepresentation(Representation rep, Revision rev, DataSet dataset){
private void insertRevisionAsLatestForRepresentation(Representation rep, Revision rev, DataSet dataset) {
dataSetDAO.insertLatestProviderDatasetRepresentationInfo(dataset.getId(), dataset.getProviderId(),
rep.getCloudId(), rep.getRepresentationName(), rev.getRevisionName(), rev.getRevisionProviderId(), rev.getCreationTimeStamp(), rep.getVersion(),
rev.isAcceptance(), rev.isPublished(), rev.isDeleted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,29 @@ public void deleteRecord(String cloudId)
dPId = repVersion.getDataProvider();
representationIndexer.removeRecordRepresentations(cloudId, uis.getProvider(dPId).getPartitionKey());
}
for (File f : repVersion.getFiles()) {
try {
contentDAO.deleteContent(FileUtils.generateKeyForFile(cloudId, repVersion.getRepresentationName(),
repVersion.getVersion(), f.getFileName()),f.getFileStorage());
} catch (FileNotExistsException ex) {
LOGGER.warn(
"File {} was found in representation {}-{}-{} but no content of such file was found",
f.getFileName(), cloudId, repVersion.getRepresentationName(), repVersion.getVersion());
}
}
removeFilesFromRepresentationVersion(cloudId, repVersion);
removeRepresentationAssignmentFromDataSets(cloudId, repVersion);
deleteRepresentationRevision(cloudId, repVersion);
recordDAO.deleteRepresentation(cloudId, repVersion.getRepresentationName(), repVersion.getVersion());
}
recordDAO.deleteRecord(cloudId);
} else {
throw new RecordNotExistsException(cloudId);
}
}

private void removeFilesFromRepresentationVersion(String cloudId, Representation repVersion) {
for (File f : repVersion.getFiles()) {
try {
contentDAO.deleteContent(FileUtils.generateKeyForFile(cloudId, repVersion.getRepresentationName(),
repVersion.getVersion(), f.getFileName()), f.getFileStorage());
} catch (FileNotExistsException ex) {
LOGGER.warn(
"File {} was found in representation {}-{}-{} but no content of such file was found",
f.getFileName(), cloudId, repVersion.getRepresentationName(), repVersion.getVersion());
}
}
}


/**
* @inheritDoc
Expand All @@ -140,33 +146,19 @@ public void deleteRepresentation(String globalId, String schema)
dPId = rep.getDataProvider();
representationIndexer.removeRepresentation(globalId, schema, uis.getProvider(dPId).getPartitionKey());
}
for (File f : rep.getFiles()) {
try {
contentDAO.deleteContent(FileUtils.generateKeyForFile(globalId, schema, rep.getVersion(), f
.getFileName()),f.getFileStorage());
} catch (FileNotExistsException ex) {
LOGGER.warn("File {} was found in representation {}-{}-{} but no content of such file was found",
f.getFileName(), globalId, rep.getRepresentationName(), rep.getVersion());
}
}

for (Revision r : rep.getRevisions()) {
recordDAO.deleteRepresentationRevision(globalId, schema, rep.getVersion(), r.getRevisionProviderId(), r.getRevisionName(), r.getCreationTimeStamp());
}

Collection<CompoundDataSetId> compoundDataSetIds = dataSetDAO.getDataSetAssignmentsByRepresentationVersion(globalId, schema, rep.getVersion());
if (!compoundDataSetIds.isEmpty()) {
for (CompoundDataSetId compoundDataSetId : compoundDataSetIds) {
try {
dataSetService.removeAssignment(compoundDataSetId.getDataSetProviderId(), compoundDataSetId.getDataSetId(), globalId, schema, rep.getVersion());
} catch (DataSetNotExistsException e) {
}
}
}
removeFilesFromRepresentationVersion(globalId, rep);
removeRepresentationAssignmentFromDataSets(globalId, rep);
deleteRepresentationRevision(globalId, rep);
}
recordDAO.deleteRepresentation(globalId, schema);
}

private void deleteRepresentationRevision(String globalId, Representation rep) {
for (Revision r : rep.getRevisions()) {
recordDAO.deleteRepresentationRevision(globalId, rep.getRepresentationName(), rep.getVersion(), r.getRevisionProviderId(), r.getRevisionName(), r.getCreationTimeStamp());
}
}


/**
* @inheritDoc
Expand Down Expand Up @@ -238,30 +230,23 @@ public void deleteRepresentation(String globalId, String schema, String version)
representationIndexer.removeRepresentationVersion(version, uis.getProvider(rep.getDataProvider())
.getPartitionKey());

for (File f : rep.getFiles()) {
try {
contentDAO.deleteContent(FileUtils.generateKeyForFile(globalId, schema, version, f.getFileName()),f.getFileStorage());
} catch (FileNotExistsException ex) {
LOGGER.warn("File {} was found in representation {}-{}-{} but no content of such file was found",
f.getFileName(), globalId, rep.getRepresentationName(), rep.getVersion());
}
}
removeFilesFromRepresentationVersion(globalId, rep);
removeRepresentationAssignmentFromDataSets(globalId, rep);
deleteRepresentationRevision(globalId, rep);
recordDAO.deleteRepresentation(globalId, schema, version);

for (Revision r : rep.getRevisions()) {
recordDAO.deleteRepresentationRevision(globalId, schema, version, r.getRevisionProviderId(), r.getRevisionName(), r.getCreationTimeStamp());
}
}

Collection<CompoundDataSetId> compoundDataSetIds = dataSetDAO.getDataSetAssignmentsByRepresentationVersion(globalId, schema, version);
private void removeRepresentationAssignmentFromDataSets(String globalId, Representation representation) throws RepresentationNotExistsException {
Collection<CompoundDataSetId> compoundDataSetIds = dataSetDAO.getDataSetAssignmentsByRepresentationVersion(globalId, representation.getRepresentationName(), representation.getVersion());
if (!compoundDataSetIds.isEmpty()) {
for (CompoundDataSetId compoundDataSetId : compoundDataSetIds) {
try {
dataSetService.removeAssignment(compoundDataSetId.getDataSetProviderId(), compoundDataSetId.getDataSetId(), globalId, schema, version);
dataSetService.removeAssignment(compoundDataSetId.getDataSetProviderId(), compoundDataSetId.getDataSetId(), globalId, representation.getRepresentationName(), representation.getVersion());
} catch (DataSetNotExistsException e) {
}
}
}
recordDAO.deleteRepresentation(globalId, schema, version);

}


Expand Down Expand Up @@ -330,7 +315,7 @@ public boolean putContent(String globalId, String schema, String version, File f
String keyForFile = FileUtils.generateKeyForFile(globalId, schema, version, file.getFileName());
PutResult result;
try {
result = contentDAO.putContent(keyForFile, content,file.getFileStorage());
result = contentDAO.putContent(keyForFile, content, file.getFileStorage());
} catch (IOException ex) {
throw new SystemException(ex);
}
Expand Down Expand Up @@ -378,8 +363,8 @@ public String getContent(String globalId, String schema, String version, String
Representation rep = getRepresentation(globalId, schema, version);
File file = findFileInRepresentation(rep, fileName);
try {
contentDAO.getContent(FileUtils.generateKeyForFile(globalId, schema, version, fileName), -1, -1, os,
file.getFileStorage());
contentDAO.getContent(FileUtils.generateKeyForFile(globalId, schema, version, fileName), -1, -1, os,
file.getFileStorage());
} catch (IOException ex) {
throw new SystemException(ex);
}
Expand All @@ -400,7 +385,7 @@ public void deleteContent(String globalId, String schema, String version, String
}
recordDAO.removeFileFromRepresentation(globalId, schema, version, fileName);
File file = findFileInRepresentation(representation, fileName);
contentDAO.deleteContent(FileUtils.generateKeyForFile(globalId, schema, version, fileName),file.getFileStorage());
contentDAO.deleteContent(FileUtils.generateKeyForFile(globalId, schema, version, fileName), file.getFileStorage());
}


Expand All @@ -423,14 +408,14 @@ public Representation copyRepresentation(String globalId, String schema, String
File copiedFile = new File(srcFile);
try {
contentDAO.copyContent(FileUtils.generateKeyForFile(globalId, schema, version, srcFile.getFileName()),
FileUtils.generateKeyForFile(globalId, schema, copiedRep.getVersion(), copiedFile.getFileName()),
FileUtils.generateKeyForFile(globalId, schema, copiedRep.getVersion(), copiedFile.getFileName()),
srcFile.getFileStorage());
} catch (FileNotExistsException ex) {
LOGGER.warn("File {} was found in representation {}-{}-{} but no content of such file was found",
srcFile.getFileName(), globalId, schema, version);
} catch (FileAlreadyExistsException ex) {
LOGGER.warn("File already exists in newly created representation?", copiedFile.getFileName(), globalId,
schema, copiedRep.getVersion());
schema, copiedRep.getVersion());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Loading