This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit e679cfc2 authored by Eduard Frankford's avatar Eduard Frankford
Browse files

Merge branch 'bugfix/fix-export-to-artemis' into 'development'

[ Bugfix ] - Fix export to artemis

See merge request sharing/codeability-sharing-platform!73
parents 94dfc866 f7acc411
Branches
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
......@@ -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());
null);
}
/**
* 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;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment