forked from Archives/Athou_commafeed
preserve order during opml import (#707)
This commit is contained in:
@@ -38,8 +38,8 @@ public class OPMLImporter {
|
|||||||
try {
|
try {
|
||||||
Opml feed = (Opml) input.build(new StringReader(xml));
|
Opml feed = (Opml) input.build(new StringReader(xml));
|
||||||
List<Outline> outlines = feed.getOutlines();
|
List<Outline> outlines = feed.getOutlines();
|
||||||
for (Outline outline : outlines) {
|
for (int i = 0; i < outlines.size(); i++) {
|
||||||
handleOutline(user, outline, null);
|
handleOutline(user, outlines.get(i), null, i);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
@@ -47,7 +47,7 @@ public class OPMLImporter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleOutline(User user, Outline outline, FeedCategory parent) {
|
private void handleOutline(User user, Outline outline, FeedCategory parent, int position) {
|
||||||
List<Outline> children = outline.getChildren();
|
List<Outline> children = outline.getChildren();
|
||||||
if (CollectionUtils.isNotEmpty(children)) {
|
if (CollectionUtils.isNotEmpty(children)) {
|
||||||
String name = FeedUtils.truncate(outline.getText(), 128);
|
String name = FeedUtils.truncate(outline.getText(), 128);
|
||||||
@@ -64,11 +64,12 @@ public class OPMLImporter {
|
|||||||
category.setName(name);
|
category.setName(name);
|
||||||
category.setParent(parent);
|
category.setParent(parent);
|
||||||
category.setUser(user);
|
category.setUser(user);
|
||||||
|
category.setPosition(position);
|
||||||
feedCategoryDAO.saveOrUpdate(category);
|
feedCategoryDAO.saveOrUpdate(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Outline child : children) {
|
for (int i = 0; i < children.size(); i++) {
|
||||||
handleOutline(user, child, category);
|
handleOutline(user, children.get(i), category, i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String name = FeedUtils.truncate(outline.getText(), 128);
|
String name = FeedUtils.truncate(outline.getText(), 128);
|
||||||
@@ -80,7 +81,7 @@ public class OPMLImporter {
|
|||||||
}
|
}
|
||||||
// make sure we continue with the import process even if a feed failed
|
// make sure we continue with the import process even if a feed failed
|
||||||
try {
|
try {
|
||||||
feedSubscriptionService.subscribe(user, outline.getXmlUrl(), name, parent);
|
feedSubscriptionService.subscribe(user, outline.getXmlUrl(), name, parent, position);
|
||||||
} catch (FeedSubscriptionException e) {
|
} catch (FeedSubscriptionException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -44,7 +44,15 @@ public class FeedSubscriptionService {
|
|||||||
private final CacheService cache;
|
private final CacheService cache;
|
||||||
private final CommaFeedConfiguration config;
|
private final CommaFeedConfiguration config;
|
||||||
|
|
||||||
public Feed subscribe(User user, String url, String title, FeedCategory category) {
|
public Feed subscribe(User user, String url, String title) {
|
||||||
|
return subscribe(user, url, title, null, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Feed subscribe(User user, String url, String title, FeedCategory parent) {
|
||||||
|
return subscribe(user, url, title, parent, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Feed subscribe(User user, String url, String title, FeedCategory category, int position) {
|
||||||
|
|
||||||
final String pubUrl = config.getApplicationSettings().getPublicUrl();
|
final String pubUrl = config.getApplicationSettings().getPublicUrl();
|
||||||
if (StringUtils.isBlank(pubUrl)) {
|
if (StringUtils.isBlank(pubUrl)) {
|
||||||
@@ -63,7 +71,7 @@ public class FeedSubscriptionService {
|
|||||||
sub.setUser(user);
|
sub.setUser(user);
|
||||||
}
|
}
|
||||||
sub.setCategory(category);
|
sub.setCategory(category);
|
||||||
sub.setPosition(0);
|
sub.setPosition(position);
|
||||||
sub.setTitle(FeedUtils.truncate(title, 128));
|
sub.setTitle(FeedUtils.truncate(title, 128));
|
||||||
feedSubscriptionDAO.saveOrUpdate(sub);
|
feedSubscriptionDAO.saveOrUpdate(sub);
|
||||||
|
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ public class FeedREST {
|
|||||||
url = fetchFeedInternal(url).getUrl();
|
url = fetchFeedInternal(url).getUrl();
|
||||||
|
|
||||||
FeedInfo info = fetchFeedInternal(url);
|
FeedInfo info = fetchFeedInternal(url);
|
||||||
feedSubscriptionService.subscribe(user, info.getUrl(), info.getTitle(), null);
|
feedSubscriptionService.subscribe(user, info.getUrl(), info.getTitle());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Could not subscribe to url {} : {}", url, e.getMessage());
|
log.info("Could not subscribe to url {} : {}", url, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class OPMLImporterTest {
|
|||||||
importer.importOpml(user, xml);
|
importer.importOpml(user, xml);
|
||||||
|
|
||||||
Mockito.verify(feedSubscriptionService).subscribe(Mockito.eq(user), Mockito.anyString(), Mockito.anyString(),
|
Mockito.verify(feedSubscriptionService).subscribe(Mockito.eq(user), Mockito.anyString(), Mockito.anyString(),
|
||||||
Mockito.any(FeedCategory.class));
|
Mockito.any(FeedCategory.class), Mockito.anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user