private void manageProfile(TaskContext context) {
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
Container current = fabricService.get().getCurrentContainer();
ProfileData profileData = createProfileData(context);
String profileId = context.getConfiguration().get(TEMPLATE_PROFILE_PROPERTY_NAME) + "-" + name;
Version version = current.getVersion();
String versionId = version.getId();
// [TODO] Revisit lock in ProfileTemplateWorker
try {
if (lock.acquire(60, TimeUnit.SECONDS)) {
if (profileData.isEmpty()) {
if (version.hasProfile(profileId)) {
profileService.deleteProfile(fabricService.get(), versionId, profileId, true);
}
return;
}
Profile managedProfile;
if (version.hasProfile(profileId)) {
Profile profile = profileService.getRequiredProfile(versionId, profileId);
ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
builder.setFileConfigurations(profileData.getFiles());
managedProfile = profileService.updateProfile(builder.getProfile());
} else {