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

Capp-10752 Delete documents before deleting alias #2

Merged
merged 2 commits into from
Dec 23, 2018
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 @@ -56,6 +56,7 @@ public class AliasServiceImpl implements AliasService {
@Inject
private DocumentService documentService;

@Override
public List<Alias> addAll(PushApplication pushApplication, List<Alias> aliases, boolean oauth2) {
logger.debug("OAuth2 flag is: " + oauth2);
List<Alias> aliasList = new ArrayList<>();
Expand Down Expand Up @@ -99,17 +100,15 @@ public List<UserKey> remove(UUID pushApplicationId, UUID userId, boolean destruc
}

private List<UserKey> remove(UUID pushApplicationId, String alias, boolean destructive) {
// Remove any aliases belong to user_id
List<UserKey> removed = aliasDao.remove(pushApplicationId, alias);
// TODO - Remove from cluster cache

// TODO - Remove from cluster cache
if (destructive) {
// Remove user from keyCloak
keycloakService.delete(alias);

documentService.delete(pushApplicationId, find(pushApplicationId.toString(), alias));
}
return removed;
// Remove any aliases belong to user_id
return aliasDao.remove(pushApplicationId, alias);
}

@Override
Expand Down Expand Up @@ -142,6 +141,7 @@ public boolean registered(String alias) {
* @param alias alias name
* @param fqdn domain / team name.
*/
@Override
public Associated associated(String alias, String fqdn) {
PushApplication pushApplication = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.jboss.aerogear.unifiedpush.api.Alias;
import org.jboss.aerogear.unifiedpush.api.PushApplication;
import org.jboss.aerogear.unifiedpush.api.document.DocumentMetadata;
import org.jboss.aerogear.unifiedpush.service.annotations.LoggedInUser;
import org.jboss.aerogear.unifiedpush.service.impl.AliasServiceImpl.Associated;
import org.jboss.aerogear.unifiedpush.service.impl.spring.OAuth2Configuration;
Expand All @@ -40,6 +41,8 @@ public class AliasServiceTest extends AbstractCassandraServiceTest {

@Inject
private AliasService aliasService;
@Inject
private DocumentService documentService;

@Test
@Transactional
Expand Down Expand Up @@ -104,7 +107,8 @@ public void testRemoveAlias() throws IOException {
PushApplication pushApplication = new PushApplication();
UUID pushAppId = UUID.fromString(pushApplication.getPushApplicationID());

Alias[] legacyAliases = new Alias[] { new Alias(pushAppId, UUIDs.timeBased(), "Supprot@AeroGear.org"),
UUID firstGuid = UUIDs.timeBased();
Alias[] legacyAliases = new Alias[] { new Alias(pushAppId, firstGuid, "Supprot@AeroGear.org"),
new Alias(pushAppId, UUIDs.timeBased(), "Test@AeroGear.org"),
new Alias(pushAppId, UUIDs.timeBased(), "Help@AeroGear.org") };
List<Alias> aliasList = Arrays.asList(legacyAliases);
Expand All @@ -117,11 +121,14 @@ public void testRemoveAlias() throws IOException {
assertThat(aliasService.find(alias.getPushApplicationId(), alias.getId())).isNotNull();
});

documentService.save(new DocumentMetadata(pushAppId, getClass().getSimpleName(), firstGuid),
"doc1", "test_id");

// Delete alias
aliasService.remove(pushAppId, legacyAliases[0].getEmail());
aliasService.remove(pushAppId, firstGuid, true);

// Validate Alias is missing
assertThat(aliasService.find(legacyAliases[0].getPushApplicationId(), legacyAliases[0].getId())).isNull();
assertThat(aliasService.find(pushAppId, firstGuid)).isNull();

}

Expand Down