This is the codeAbility Sharing Platform! Learn more about the
codeAbility Sharing Platform
.
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
codeAbility Sharing Platform
Manage
Activity
Members
Labels
Plan
Issues
43
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
development
sharing
codeAbility Sharing Platform
Commits
51c96934
Commit
51c96934
authored
3 years ago
by
Daniel Crazzolara
Browse files
Options
Downloads
Patches
Plain Diff
Fixed files not included
parent
148154d9
2 merge requests
!74
Update Master November
,
!73
[ Bugfix ] - Fix export to artemis
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java
+38
-38
38 additions, 38 deletions
...a/at/ac/uibk/gitsearch/service/ShoppingBasketService.java
with
38 additions
and
38 deletions
src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java
+
38
−
38
View file @
51c96934
...
...
@@ -44,12 +44,12 @@ import at.ac.uibk.gitsearch.security.jwt.TokenProvider.GitLabAccessInfo;
*/
@Service
public
class
ShoppingBasketService
{
@Autowired
private
PluginManagementService
pluginManagementService
;
@Autowired
private
GitLabRepository
gitLabRepository
;
public
static
class
ShoppingBasketRedirectInfoDTO
{
private
String
redirectURL
;
/**
...
...
@@ -65,22 +65,22 @@ public class ShoppingBasketService {
this
.
redirectURL
=
redirectURL
;
}
}
public
static
class
ShoppingBasketInfoDTO
{
private
SearchResultDTO
[]
itemInfos
;
private
String
plugin
;
private
String
action
;
public
ShoppingBasketInfoDTO
(
SearchResultDTO
[]
itemInfos
)
{
super
();
this
.
itemInfos
=
itemInfos
;
}
public
ShoppingBasketInfoDTO
()
{
// JSON
}
/**
* @return the itemInfos
...
...
@@ -131,13 +131,13 @@ public class ShoppingBasketService {
public
static
class
ItemInfoDTO
{
String
exerciseID
;
String
gitLabURL
;
public
ItemInfoDTO
(
String
exerciseID
,
String
gitLabURl
)
{
super
();
this
.
exerciseID
=
exerciseID
;
this
.
gitLabURL
=
gitLabURl
;
}
public
ItemInfoDTO
()
{
// JSON
}
...
...
@@ -167,7 +167,7 @@ public class ShoppingBasketService {
}
}
}
/**
* holds further info for shopping basket.
* @author Michael Breu
...
...
@@ -182,11 +182,11 @@ public class ShoppingBasketService {
}
public
ExtendedShoppingBasket
()
{
}
private
ShoppingBasketInfoDTO
shoppingBasket
;
private
Optional
<
GitLabAccessInfo
>
gitLabAccessInfo
;
/**
* token valid until (msecs since 1.1.1970)
*/
...
...
@@ -223,7 +223,7 @@ public class ShoppingBasketService {
return
tokenValidUntil
;
}
}
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
ShoppingBasketService
.
class
);
...
...
@@ -231,7 +231,7 @@ public class ShoppingBasketService {
public
ShoppingBasketService
()
{
// JSON
}
public
ShoppingBasket
getBasket
(
String
basketToken
)
{
if
(
basketToken
==
null
)
{
log
.
warn
(
"Basket for null not found"
);
...
...
@@ -242,7 +242,7 @@ public class ShoppingBasketService {
log
.
warn
(
"Basket {} not found"
,
basketToken
);
return
null
;
}
List
<
org
.
codeability
.
sharing
.
plugins
.
api
.
search
.
SearchResultDTO
>
result
=
new
ArrayList
<>();
for
(
SearchResultDTO
hit:
basketInfo
.
getShoppingBasket
().
getItemInfos
())
{
result
.
add
(
convertFrom
(
hit
));
...
...
@@ -256,17 +256,17 @@ public class ShoppingBasketService {
log
.
info
(
"Basket {} is delivered"
,
basketToken
);
return
shoppingBasket
;
}
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
static
{
objectMapper
.
registerModule
(
new
JavaTimeModule
());
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
}
private
org
.
codeability
.
sharing
.
plugins
.
api
.
search
.
SearchResultDTO
convertFrom
(
SearchResultDTO
hit
)
{
try
{
return
objectMapper
.
readValue
(
objectMapper
.
writeValueAsString
(
hit
),
org
.
codeability
.
sharing
.
plugins
.
api
.
search
.
SearchResultDTO
.
class
);
}
catch
(
JsonMappingException
e
)
{
...
...
@@ -277,22 +277,22 @@ public class ShoppingBasketService {
return
null
;
}
}
public
InputStream
getRepositoryZip
(
String
basketToken
,
int
position
)
throws
GitLabApiException
,
IOException
{
final
@Nullable
ExtendedShoppingBasket
basketInfo
=
basketCache
.
getIfPresent
(
basketToken
);
ShoppingBasket
basket
=
getBasket
(
basketToken
);
ShoppingBasket
basket
=
getBasket
(
basketToken
);
final
GitLabApi
gitLabApi
=
basketInfo
==
null
?
gitLabRepository
.
getGitLabApi
(
Optional
.
empty
()):
gitLabRepository
.
getGitLabApi
(
basketInfo
.
getGitLabAccessInfo
());
return
rePackageGitLabProjectZip
(
new
ZipInputStream
(
gitLabApi
.
getRepositoryApi
().
getRepositoryArchive
(
basket
.
exerciseInfo
[
position
].
getProject
().
getProjectId
(),
"HEAD"
,
"zip"
)),
"from project "
+
basket
.
exerciseInfo
[
position
].
getProject
().
getProjectId
(),
new
String
[]
{},
basket
.
exerciseInfo
[
position
].
getFile
().
getPath
()
);
""
);
}
/**
* chops of the main folder, and brings every file one level up. Also deleting
* all plain files in main folder.
*
*
* @param zipIn the zip to be repackaged
* @param originalLocation the original location. For debug purposes only.
* @param filterOut an array of file or foldernames that should be filtered away
...
...
@@ -312,7 +312,7 @@ public class ShoppingBasketService {
if
(
zipInEntry
.
isDirectory
())
{
// main directory is prefix to all entries
prefix
=
zipInEntry
.
getName
();
}
while
(
zipInEntry
!=
null
)
{
String
fileName
=
zipInEntry
.
getName
();
if
(
fileName
.
startsWith
(
prefix
))
{
...
...
@@ -323,7 +323,7 @@ public class ShoppingBasketService {
if
(!
StringUtils
.
isEmpty
(
newName
)
&&
!
filterOut
(
newName
,
filterOut
))
{
ZipEntry
zipOutEntry
=
new
ZipEntry
(
newName
);
if
(
zipInEntry
.
isDirectory
())
{
log
.
debug
(
"ignoring directory {}"
,
fileName
);
log
.
debug
(
"ignoring directory {}"
,
fileName
);
zipOut
.
putNextEntry
(
zipOutEntry
);
}
else
{
zipOut
.
putNextEntry
(
zipOutEntry
);
...
...
@@ -343,14 +343,14 @@ public class ShoppingBasketService {
return
pis
;
}
public
String
getExerciseFolderPath
(
String
exercisesPath
)
{
if
(
exercisesPath
==
null
)
return
""
;
int
slashPos
=
exercisesPath
.
lastIndexOf
(
'/'
);
if
(
slashPos
<
0
)
return
""
;
// root metadata
return
exercisesPath
.
substring
(
0
,
slashPos
);
}
/**
* shortens the fileName by the pathPrefix. Returns null, if fileName does not start with path prefix.
* @param fileName the file name
...
...
@@ -375,7 +375,7 @@ public class ShoppingBasketService {
}
return
false
;
}
public
static
final
Duration
BASKET_EXPIRY_INTERVAL
=
Duration
.
ofMinutes
(
60
);
/**
* this is a cache for shopping baskets. Entries expires after BASKET_EXPIRY_INTERVAL.
...
...
@@ -390,23 +390,23 @@ public class ShoppingBasketService {
return
null
;
}
});
public
ShoppingBasketRedirectInfoDTO
getRedirectInfo
(
ShoppingBasketInfoDTO
basket
,
String
baseURL
)
{
UUID
random
=
UUID
.
randomUUID
();
long
tokenValidUntil
=
System
.
currentTimeMillis
()
+
BASKET_EXPIRY_INTERVAL
.
toMillis
();
basketCache
.
put
(
random
.
toString
(),
new
ExtendedShoppingBasket
(
basket
,
gitLabRepository
.
getGitLabAccessInfo
(),
tokenValidUntil
));
ShoppingBasketRedirectInfoDTO
result
=
new
ShoppingBasketRedirectInfoDTO
();
result
.
setRedirectURL
(
pluginManagementService
.
getRedirectURL
(
basket
.
getPlugin
(),
basket
.
getAction
())
+
"/"
+
random
.
toString
()
+
"?returnURL="
+
baseURL
+
"?returnURL="
+
baseURL
+
"&apiBaseURL="
+
baseURL
+
"/api/pluginIF/v0.1"
);
return
result
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment