-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from EGA-archive/bugfix/byte_length_missing
Fixing bytes length for localEGA profile
- Loading branch information
Showing
10 changed files
with
148 additions
and
131 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...data-api-dataedge/src/main/java/eu/elixir/ega/ebi/dataedge/service/FileLengthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2016 ELIXIR EGA | ||
* | ||
* 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 eu.elixir.ega.ebi.dataedge.service; | ||
|
||
import eu.elixir.ega.ebi.shared.dto.File; | ||
|
||
/** | ||
* @author amohan | ||
*/ | ||
public interface FileLengthService { | ||
|
||
long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate); | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...edge/src/main/java/eu/elixir/ega/ebi/dataedge/service/internal/FileLengthServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2016 ELIXIR EGA | ||
* | ||
* 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 eu.elixir.ega.ebi.dataedge.service.internal; | ||
|
||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import eu.elixir.ega.ebi.dataedge.service.FileLengthService; | ||
import eu.elixir.ega.ebi.shared.dto.File; | ||
|
||
/** | ||
* @author amohan | ||
*/ | ||
@Service | ||
@Primary | ||
@Profile("!LocalEGA") | ||
public class FileLengthServiceImpl implements FileLengthService { | ||
|
||
@Override | ||
public long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate) { | ||
long length = 0; | ||
|
||
// EncryptionFormat | ||
// If destinationFormat is encrypted then we add extra 16 byte to store the IV. | ||
int prefix = 16; | ||
if (destinationFormat.equalsIgnoreCase("plain")) | ||
prefix = 0; | ||
|
||
// Range specified? | ||
// The AES encrypted data has a 16 byte random IV at the start, so to | ||
// get the correct (raw) file length we need to remove this 16 byte | ||
// prefix. | ||
if (startCoordinate > 0 || endCoordinate > 0) { | ||
length = endCoordinate - startCoordinate; | ||
} else { | ||
length = reqFile.getFileSize() - 16; | ||
} | ||
|
||
return (length + prefix); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
.../main/java/eu/elixir/ega/ebi/dataedge/service/internal/LocalEGAFileLengthServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016 ELIXIR EGA | ||
* | ||
* 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 eu.elixir.ega.ebi.dataedge.service.internal; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import eu.elixir.ega.ebi.dataedge.service.FileLengthService; | ||
import eu.elixir.ega.ebi.shared.dto.File; | ||
|
||
/** | ||
* @author amohan | ||
*/ | ||
@Service | ||
@Profile("LocalEGA") | ||
public class LocalEGAFileLengthServiceImpl implements FileLengthService { | ||
|
||
@Override | ||
public long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate) { | ||
long length = 0; | ||
|
||
if (startCoordinate > 0 || endCoordinate > 0) { | ||
length = endCoordinate - startCoordinate; | ||
} else { | ||
// Removing 32 bytes from the actual file size because when the file is stored in S3, | ||
// the sha256sum is added at the beginning so the length would be -32 | ||
length = reqFile.getFileSize() - 32; | ||
} | ||
|
||
return length; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters