Fix resolving link to non-existing default environment.

If the default environment no longer exists, create a new environment
first when trying to add an application to an environment.

Closes-Bug: #1295568
Change-Id: Icbe29e6b23b476f7d8f1a5de7938812fd44e493a